Where Clause Error In The DoCmd.OpenReport

C

cheer

Error prompt at below code

DoCmd.OpenReport "Report_Machine_Utilisation_Time", acViewPreview, ,
"OpnStartTime between #" & strStartDate & "# And #" & strEndDate & "#"

a) Error message: data type mismatch in criteria expression

b) Both strStartDate and strEndDate is value from TextBox

c) Example of strStartDate or strEndDate value is "11/13/2009 08:00:00"

d) Try before
DoCmd.OpenReport "Report_Machine_Utilisation_Time", acViewPreview, ,
"OpnStartTime between " & cdate(strStartDate) & " And " & cdate(strEndDate) &
""

OR

DoCmd.OpenReport "Report_Machine_Utilisation_Time", acViewPreview, ,
"OpnStartTime between " & Format(strStartDate, "\#mm/dd/yyyy hh:mm:ss\#") & "
And " & Format(strEndDate, "\#mm/dd/yyyy hh:mm:ss\#") & ""

but the same error message prompt

e) OpnStartTime is date field

f) I am using MS Access 2000

g) Tested sample value #11/10/2009# And #11/11/2009# at the query used in the
report. The query works.

Any further advice why the above OpenReport code doesn't work ?
 
K

Ken Snell

Format the date values as "mm/dd/yyyy" format:

DoCmd.OpenReport "Report_Machine_Utilisation_Time", acViewPreview, ,
"OpnStartTime between #" & Format(strStartDate, "mm\/dd\/yyyy") & "# And #"
& Format(strEndDate, "mm\/dd\/yyyy") & "#"
 

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