Easy enough, but there are some 'gotchas'.
Create the following function in a module. Change the names of the query and
spreadsheet as appropriate. Also watch out for word wrapping as acExport
should be on the same line as TransferSpreadsheet:
Function fSendFileAt4am()
If Time() >= #4:00:00 AM# And Time() < #5:00:00 AM# Then
DoCmd.SetWarnings False
DoCmd.TransferSpreadsheet acExport, , "TheQueryName",
"H:\IS\4amExport.xls"
DoCmd.SetWarnings True
End If
End Function
Then in a form that must be open (but not necessarily visible) put the
following in the On Timer Event using the Code Builder: fSendFileAt4am
It should look like:
Private Sub Form_Timer()
fSendFileAt4am
End Sub
In the Timer Interval put the following which equals one hour: 3600000
Now IF the database is open and IF the form is open, the query should be
exported to a spreadsheet somewhere between 4am and 5am every morning. You
could cut down on the Timer Interval and the times that are checked; however,
that will cause the Timer to fire more often.