Printing a query parameter

D

Dorian

When I have a parameter query such as:
SELECT * FROM tblTable WHERE MyDate = [My date];
and I open this query with
DoCmd.OpenQuery Me!cmbQueries, acViewPreview, acReadOnly
is there any way I can display the contents of [My date] on the page?

-- Dorian
"Give someone a fish and they eat for a day; teach someone to fish and they
eat for a lifetime".
 
K

KARL DEWEY

Yep.
SELECT *, [My date] AS [Report Date] FROM tblTable WHERE MyDate = [My date];

It is best to copy the parameter so as not to have spelling mistakes.
 
D

Dale Fye

By virtue of your SELECT statement, you are displaying the field [MyDate] in
the Query results.

But since you indicate you want to print this and include the parameter [My
date] on the page, I'd recommend something like:

1. Create a report based on the table
2. Delete the RecordSource for the report
3. In the Reports Open event, present the user with an input box to enter a
value for [My Date]. Then, also in the Open event, I would reset the reports
RecordSource to your SQL statement and change the reports caption to reflect
the date you entered

It might look like:

Private Sub Report_Open(Cancel As Integer)

Dim strDate As Date
Dim strSQL As String

Do
strDate = InputBox("My date?")
If IsDate(strDate) = True Then Exit Do
Loop

strSQL = "SELECT * FROM tbl_Activities " _
& "WHERE [MyDate] = #" & CDate(strDate) & "#"
Me.RecordSource = strSQL
Me.Caption = "Activity report, MyDate = " & strDate

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top