DoCmd.OpenReport with Where Condition on Date
Posted on 2010-11-17
I'm working in VB2008, but using Microsoft.Office.Interop.Access.Application to print reports from Access.
I have a report with a query as the recordsource. I'm trying to fill my report based on a date field (RptDate) in the query. I have tried many different ways to pass the date parameter in the "Where condition" to the report, but without success. The report is printed either with all records in the query or no records.
For example, one of the attempts:
Dim Date1 As String
Date1 = dtp1.Value.ToShortDateString()
DoCmd.OpenReport "rptReport", AcView.acViewNormal, , "RptDate= #" & Date1 & "#"
This example results in a report showing all records in the query instead of only records with the date requested.
Can someone provide the correct method to use?