Date parameter works on query but not on report?

mschwent

Registered User.
Local time
Today, 22:21
Joined
Apr 19, 2006
Messages
18
I have a calendar control on a form so the user can select start and end dates for a report. In the after_update event of the calendar it puts the dates in text boxes, format dd-mm-yyyy. This part works fine.

But when the user loads the report (which should use these dates) the report loads data for all dates, whether they are inside the range or not.

But when I double click the query it asks me to input these parameters and then gives me the desired data, so my problem is somehow the form is not sending the proper parameters to the report, and the report is not asking for the right parameters.

Here's the code to generate the report:
Code:
Private Sub cmdACCEPT_Click()
DoCmd.OpenReport "conRelatório", acViewPreview
End Sub

And here's the query the report is built on:
Code:
SELECT [OK_PEÇAS].[SEQUENCE], [OK_PEÇAS].[CUSTOMPN], [OK_PEÇAS].[ESQUERDO], [OK_PEÇAS].[DIREITO], [OK_PEÇAS].[DATA]
FROM OK_PEÇAS
WHERE [OK_PEÇAS].[DATA] Between cdate([forms]![frmCalendar].[DATA_inicio]) And cdate([forms]![frmCalendar].[DATA_final]);

forms!frmCalendar.data_inicio and ...final do hold a text string in the format dd-mm-yyyy at the time the report is called.

Can anyone help me out with this?
 
A, is the form still open while the Report is loading
B/ Why are the date fields text strings?
 
Yes, the form remains open. And the date fields are text strings because that is the way they are passed from the calendar applet the form is using. I didn't write the code for the calendar and, if possible, I'd prefer not to touch it.

If I can't convert the strings to dates in the SQL query, I can probably convert them to dates in the After_Update event of the calendar, but when I have a choice I prefer to do everything using SQL.
 

Users who are viewing this thread

Back
Top Bottom