Automatic Reporting

J

Jadabug

Is there a way to set up a report to automatically run on a
predetermined date? For instance I would set up the report, then
select the date, and it would automatically run on that date.
 
J

John Nurick

One way is to have code that runs whenever the database is opened. It
should check the current date, the date the report needs to be run and
the date it was last run (so as not to run it every time the database
opens on the day in question), and run the report if appropriate.

I'd put the code in the Open event of the startup form, and use a record
in a little 'settings' table to store both the date it needs to be run
and the date it was last run:

tblSettings
SettingName - text*
SettingValue - text
with records
SettingName, SettingValue
"NextRunReportX", "2006/30/06"
"LastRunReportX", "2006/31/05"

Then the code would be something like this:

If (Date() => DLookup("SettingValue", "tblSettings", _
"SettingName=""NextRunReport""")) _
And ( _
(DLookup("SettingValue", "tblSettings", _
"SettingName=""NextRunReport""") _
DLookup("SettingValue", "tblSettings", _
"SettingName=""LastRunReport""") _
) Then
'The report needs to run today and hasn't already run today
'so we run it
DoCmd.OpenReport blah blah
'now update the last-run date
CurrentDB.Execute "UPDATE tblSettings " _
"SET SettingValue = '" & Format(Date(), "yyyy/mm/dd") & "' " _
"WHERE SettingName='LastRunReport';", dbFailOnError
End If

It's possible that at the time the startup form opens the database won't
be ready to run the report. In that case, use the Open event to start
the form's timer with a suitable delay, and then use the OnTime event to
launch the code that opens the report.
 
E

eos

AUTO-REPLY From George Levitt

Please allow this to confirm a system receipt of your e-mail.

I am out of the office until Wednesday morning (1/12/05) and will not be
reviewing or responding to email or voicemail until that time.

I look forward to replying to your message on Wednesday.

Thanks and warmest regards, George
 
E

eos

AUTO-REPLY From George Levitt

Please allow this to confirm a system receipt of your e-mail.

I am out of the office until Wednesday morning (1/12/05) and will not be
reviewing or responding to email or voicemail until that time.

I look forward to replying to your message on Wednesday.

Thanks and warmest regards, George
 
Top