Filter by Date

  • Thread starter Thread starter G Lam
  • Start date Start date
G

G Lam

Hi, I use a form "frmPrintDay" to ask user input a date then use that date
to print a report. I wrote a line of code as following:
DoCmd.OpenReport stDocName, acPreview, "qrySumSku",
WhereCondition:="PackDate = " & _
Forms!frmPrintDay!DayToPrint
But it did not work.
What did I do wrong?
Thank you in advance
Gary
 
G Lam said:
Hi, I use a form "frmPrintDay" to ask user input a date then use that date
to print a report. I wrote a line of code as following:
DoCmd.OpenReport stDocName, acPreview, "qrySumSku",
WhereCondition:="PackDate = " & _
Forms!frmPrintDay!DayToPrint
But it did not work.
What did I do wrong?

WhereCondition:="PackDate = #" & _
Forms!frmPrintDay!DayToPrint & "#"

You might even need a CDate() wrapped around the Forms!... part.
 
WhereCondition:="PackDate = #" & _
Forms!frmPrintDay!DayToPrint & "#"

You might even need a CDate() wrapped around the Forms!... part.

Nearly there: the date format is important and this will not work outside
USA/ Canada. See help files for date literals in Jet.

What the poster needs is

WhereCondition = "PackDate = " & _
Format(Forms!frmPrintDay!DayToPrint, "\#yyyy\-mm\-dd\#")

You can use the USA format if you prefer, "\#mm\/dd\/yyyy\#", but the
normal d/m/y will cause errors.

HTH


Tim F
 
Back
Top