Hi Mike - yes, that's exactly what I mean. In the Task Scheduler command add
"/cmd auto" after the database name. So your command string in Task
Scheduler might look like:
"C:\Program Files\Microsoft Office\Office\msaccess.exe"
"path_and_filename_of_your_mdb_or_mde" /cmd auto
Next, in the Open event of your main form, check for the "auto" command line
switch like so:
If Command = "auto" Then
'Set a global Boolean variable
gboolAutoRun = True
'Now run your macro
DoCmd.RunMacro "your_macro_name"
'Now quit Access
Application.Quit acQuitSaveNone
Else
gboolAutoRun = False
End If
Be sure to modify your macro so that it skips any dialog boxes or any other
code that might require user intervention if gboolAutoRun is True, since no
one will be there to clik "OK" or whatever! For instance, I cange all of my
error handlers to write to a log file instead of displaying a message box.
Here is the LogError routine:
Public Sub LogError(ModName As String, Number As Long, Desc As String,
Optional FileName As String)
'Log error number, description, and module/routine that generated the error
'to a text file, optionally with filename that caused error
On Error Resume Next 'Can't popup a MsgBox because this is
auto-execute
Dim strDateTime As String
Dim strLogDir As String
Dim strLogFile As String
Dim iFileNo As Integer
'Create the log directory if it doesn't exist
strLogDir = "C:\Logs"
If Dir(strLogDir, vbDirectory) = "" Then MkDir strLogDir
'Create new log filename every day
strLogFile = strLogDir & "\Log" & Format(Now(), "mmddyy") & ".txt"
strDateTime = Format(Now(), "mm-dd-yy hh:mm:ss")
iFileNo = FreeFile
Open strLogFile For Append Access Write Lock Write As #iFileNo
If Len(FileName) > 0 Then
Print #iFileNo, strDateTime; Spc(4); ModName; Spc(4); "Error " &
Number; _
Spc(4); Desc; Spc(4); FileName
Else
Print #iFileNo, strDateTime; Spc(4); ModName; Spc(4); "Error " &
Number; _
Spc(4); Desc
End If
Close #iFileNo
End Sub