Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Scheduling Access97 to start and run macro 1

Status
Not open for further replies.

chifu

IS-IT--Management
Apr 2, 2001
158
GB
Is it possible to Schedule Access97 to start at regular intervals, run a macro and close again. I suppose the scheduling could be done using AT and the closing could be done with a macro command, but how does one start the macro from a batch file.

Many Thanks.
 
You can leave your application run all the time on the computer and run the macro through the Timer event:

Sub Form_Timer()
Dim OldInterval As Long
OldInterval = Me.TimerInterval
Me.TimerInterval = 0
DoCmd.RunMacro "YourMacroName"
Me.TimerInterval = OldInterval
End Sub

Or, if you don't want to keep the application loaded all the time, you could use an additional application (SmallFile.mdb) having the a.m form in it. Set the TimerInterval to whatever interval you need. In this case:

Sub Form_Timer()
Shell "msacess.exe " & """" & "C:\Path\File.mdb"
Quit
End Sub

and the macro in your main application should finish with:
Action: RunApp
Command line: msaccess.exe C:\Path\SmallFile.mdb

Action: Quit

The two applications will open each other and the small one will trigger the main one when necessary.

You could also use the Task Scheduler. [pipe]
Daniel Vlas
Systems Consultant
danvlas@yahoo.com
 
Or you can run an Access macro from a simple Windows script file. Edit this script with your database/macro information and save with the extension .vbs. You can now run it through the Task Scheduler. (You should test run it separately first).

*************************************
Dim objAccess
Dim strPathToMDB
Dim strTableName
Dim strFilePath
Dim strMsg


' EDIT with your path and database name
strPathToMDB = "c:\Database.MDB"

' Create Access 97 Application Object
Set objAccess = CreateObject("Access.Application.8")

' Open the desired database
objAccess.OpenCurrentDatabase(strPathToMDB)

' EDIT with your Macro Name
objAccess.DoCmd.RunMacro "MacroName"

strMsg = "The macro named" & vbcrlf & " UpdateVendData" & vbcrlf & " execued successfully."
MsgBox strMsg,vbInformation,"Finished"

' Clean up
objAccess.CloseCurrentDatabase
ObjAccess.Quit
Set objAccess = Nothing


**********************************
 
Many Thanks I will try the suggestions.
 
There is a command line switch "/x:MacroName" that you can use to start a particular macro on loading.

Of course there is also the Autoexec Macro.

Sandip
shahs@microdental.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top