If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Visual Basic > Task Schedule created via VBA cannot run properly

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-18-09, 23:33
Lepanto Lepanto is offline
Registered User
 
Join Date: Jul 2003
Location: Australia
Posts: 206
Red face 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
Reply With Quote
  #2 (permalink)  
Old 08-19-09, 12:30
Teddy Teddy is offline
Purveyor of Discontent
 
Join Date: Mar 2003
Location: The Bottom of The Barrel
Posts: 6,075
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? ***
Reply With Quote
  #3 (permalink)  
Old 08-19-09, 20:12
Lepanto Lepanto is offline
Registered User
 
Join Date: Jul 2003
Location: Australia
Posts: 206
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.
Reply With Quote
  #4 (permalink)  
Old 08-20-09, 00:57
Teddy Teddy is offline
Purveyor of Discontent
 
Join Date: Mar 2003
Location: The Bottom of The Barrel
Posts: 6,075
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? ***
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On