I wrote a VBA program to create (and edit) task schedules.
The task is to run a macro inside an MS Access database.
The command line is something like this :
"c:\...\Msaccess.exe" <database name> /wrkgrp <work group file name>
/user username /pwd password /x MACRONAME
My VBA code is listed below for your reference. There should be no problem with the code because it succeeded in creating / editing task schedules.
The problem is scheduled tasks always CRASH.
They don't go beyond the flash screen. It always ends up showing
the error message "Microsoft Office Access has encountered a problem
and needs to close. We are sorry for the inconvenience."
Does anybody know what's the cause of the problem ? Thanks in advance.
__________________________________________________ ______________
Private Sub Command0_Click()
DeleteScheduledJob
strComputer = "."
Set objService = GetObject("winmgmts:\\" & strComputer)
Set objNewJob = objService.Get("Win32_ScheduledJob")
ConnectString = Mid(CurrentDb.TableDefs("tblSYstem").Connect, 11)
Pos = InStr(ConnectString, "BRIMSHR.DAT\BRIMSHRDat.mdb")
AppPath = Left(ConnectString, Pos - 1)
AppPath = AppPath & "BRIMSHR.OBJ"
If Me.Frame34 = 1 Then
errJobCreated = objNewJob.Create("c:\brimshr\brimshr.lnk", "********" & Format(Me.schedHour, "00") & Format(Me.schedMinute, "00") & "00.000000+600", True, 1 Or 2 Or 4 Or 8 Or 16 Or 32 Or 64, , , Jobid)
Else
errJobCreated = objNewJob.Create("""C:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE"" """ & AppPath & "\BRIMSHRObj.mdb"" /wrkgrp " & AppPath & "\deccSystem.mdw /user npwsadmin /x macAutoDownloadfiles", "********" & Format(Me.schedHour, "00") & Format(Me.schedMinute, "00") & "00.000000+600", True, 1 Or 2 Or 4 Or 8 Or 16, , , Jobid)
End If
If Err.Number = 0 Then
MsgBox "Schedule saved.", vbInformation
Else
MsgBox "An error occurred: " & errJobCreated
End If
End Sub