docmd.openreport wherecondition

ccordner

Active Member
Joined
Apr 28, 2010
Messages
355
Good morning

I had a date & time picker in a form, so the user could select a date and a report would then be run from Access. I had to circumvent this when they upgraded access and assume they wanted to run the report based on yesterday. I used the following code, thinking it would work:

Code:
With objaccess
    
    .AutomationSecurity = msoAutomationSecurityLow
    .Visible = False
    .OpenCurrentDatabase "\\bdifps01\Groups\Platform.Supervisor\DO NOT USE - Log (Front).accdb"
    .DoCmd.OpenReport "rptSupervisorsLogHistoric", acViewPreview, , "([DateReported]=#" & DateValue(Now() - 1) & "# And [TimeReported]>=TimeSerial(4,0,0) ) Or ([DateReported]=#" & DateValue(Now()) & "# And [TimeReported]<TimeSerial(4,0,0) )", acHidden
    .DoCmd.OutputTo acOutputReport, "rptSupervisorsLogHistoric", acFormatPDF, Folder & "\BDI Supervisors Log for " & Format(DateValue(Now() - 1), "d mmm yy") & ", Created at " & Format(Time, "hhmm") & " on " & Format(Date, "d mmm yy") & ".pdf", , False
    .DoCmd.Close acReport, "rptQuote"
    .CloseCurrentDatabase

End With

The bit that is causing the problem is this:

Code:
    .DoCmd.OpenReport "rptSupervisorsLogHistoric", acViewPreview, , "([DateReported]=#" & DateValue(Now() - 1) & "# And [TimeReported]>=TimeSerial(4,0,0) ) Or ([DateReported]=#" & DateValue(Now()) & "# And [TimeReported]<TimeSerial(4,0,0) )", acHidden

When the day is the 13th onwards, it works fine, but when it is the 1st to the 12th, it seems to swap the month and the date round and runs the report for the second of January, rather than the first of February.

Any ideas why?

Thanks
Chris
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Forum statistics

Threads
1,215,009
Messages
6,122,674
Members
449,091
Latest member
peppernaut

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top