Filter on date & time not working

G

Guest

I have a report with a query behind it, with a field called "Export Date".
The Export Date is displayed in the form of date and time, e.g. 1/30/2007
4:15:00 PM. The report contains a hidden field on it in the Detail section
called "txtExportDate".

There is a parameter form where the user enters a beginning date
(txtBeginDate) and and beginning time (txtBeginTime), so as to filter and
display only reports where the export date is on or after that date/time
combination. My code, which follows, runs without breaking, but is returning
all the records and not filtering. What is wrong that I am not seeing?
Thanks in advance.

Private Sub cmdContinue_Click()

Dim strFilter As String
Dim dtExportDate As Date
Dim strReportName As String

strReportName = "rptAuditSupport"
dtExportDate = txtBeginDate & " " & txtBeginTime
strFilter = "WHERE txtExportDate => #" & dtExportDate & "#"

DoCmd.OpenReport strReportName, acViewPreview, strFilter

End Sub
 
G

George Nicholson

1)
strFilter = "WHERE txtExportDate => #" & dtExportDate & "#"
Your WHERE clause should refer to the name of the field in the underlying
recordset/query. txtExport is the name of a textbox on the report.

2) OpenReport's 3rd argument is the name of a filter, its 4th is a WHERE
clause (without the WHERE). I think you want:
strFilter = "ExportDate => #" & dtExportDate & "#"
'WHERE removed and correction from #1 above
DoCmd.OpenReport strReportName, acViewPreview, ,strFilter 'Comma
added for unused argument


3)
Put a breakpoint on the line after
dtExportDate = txtBeginDate & " " & txtBeginTime
and see what value has been assigned to dtExportDate.

It may not be doing what you want (the addition of the space raises a red
flag for me). Maybe something like
dtExportDate = cdate(DateValue(txtBeginDate) + TimeValue(txtBeginTime))
This assumes that ExportDate is a true Date/Time field. If it isn't, this
may be a case of comparing Apples & Oranges.

HTH,
 

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