Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2003
    Location
    Australia
    Posts
    217

    Red face Unanswered: Task Schedule created via VBA cannot run properly

    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

  2. #2
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Did you test the command line before scheduling it?
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  3. #3
    Join Date
    Jul 2003
    Location
    Australia
    Posts
    217
    Of course I did. When I MANUALLY created task schedules using the same command-line, it worked. But VBA-created task schedules didn't work.

    Actually, the VBA-created task schedules worked in my PC at home.

    So, I think the IT people must have done something to the PC to cause this error to happen.

    Thanks.

  4. #4
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Are you absolutely 100% sure you're getting the command line value you think you are when executing in VBA?


    The error you're getting makes me think the task itself is firing just fine. Clearly Access is getting called, it's just not behaving. If the error isn't erroneous (lolpunlol), then you have some kind of hijinks going on with the ACTUAL command line call. I mean really, how did Access manage to throw an error if it was never called... and how would windows scheduler be responsible for what happens AFTER Access has been called, KWIM?


    Edit: Just to clarify, the problem is that the tasks themselves crash when triggered, right?
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •