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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run code at certain time 1

Status
Not open for further replies.

citychap26

Programmer
Sep 19, 2004
144
GB
Hi

I know this can be done but just forgotten how.

Say I have an MS Access database 2002. I want to kick off a piece of code at 20:30.

Do I need to create an on timer event on a form to check the current time every 5 mins or so and then once it is 20:30 kick off code? Or is there another way?

Cheers
SK
 
To avoid the the database being open all the time i create a Macro which performed the task and scheduled it in the windows envoiroment. Scheduled task should look something like....

"Msaccess Location" "Database location" /WRKGRP "Security file location" /userUSERNAME /pwdPASSWORD xMACRONAME

/WRKGRP "Security file location" is optional depending on if security has been set up for your database.

e.g.
"C:\Program Files\Microsoft Office\Office\MSACCESS.EXE" "C:\Springfield\doh.mdb" /WRKGRP "C:\Springfield\wigam.mdw" /userHomers /pwdSimpson /xCoolReactor

Hope this helps

Stephen
 
True, it could be scheduled from windows. However I wanted it to be run directly from MS Access.
 
Hi,

I tried this. It works for me:
Code:
Private Sub Form_Timer()
Dim varTargetTime As Variant
Dim datNow As Date

varTargetTime = "#" & Me.txtTargetTime.Text & "#"
datNow = Now()
If varTargetTime >= datNow Then
    MsgBox "It's time to go to work"
End If

End Sub

Notes: I created a text box called txtTargetTime.
You might want to use a different logic test
It is necessary to enter a value into the TimerInterval property of the form for this code to execute.

I hope this helps. Alan
 
You could place a button on the form, and turn the Timer On/Off

Code:
    Me.TimerInterval = 60000  'milliseconds
or 
Me.TimerInterval = 0

You could also place code in the Form_Load event.
 
I had played with timer functions but found them fiddley and prone to errors. They also relied on the Access database being constantly open and healthy on my PC. If access had accidentally been closed the update would not run. If access had crashed the update would not run. This was a particular problem when i was out of the office for a few days. To solve this i scheduled the macro, but also scheduled a forced reboot an while before.

I found the main advantage of using the Windows scheduler was i didn't have to write my own. I'm not sure if you can create a task from Access but would intrested to see it posted back if it can be done.


All the best

Stephen


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top