Originally Posted by
fishhead
thanks Shadow,
unfortunately i need to run this every 60-80 seconds.
I'm not sure what error handling means. I have a little coding experience but not a lot.
what do i do with your code above exactly?
When you use the Access Runtime, if anything goes wrong, it only has one way to deal with it: issue a runtime error and shut down. That kind of sucks if you're trying to develop and pinpoint the cause of errors, but sucks even more when your users or clients face the program turning off that way with no explanation.
Fortunately, you can tell your VBA code that if something goes wrong, instead of shutting down, to handle it in a way that will help the developer or be meaningful to the user.
The code that I showed you starts with:
Code:
On Error GoTo Err_Handle
That just means: "if you encounter any problems, then skip down to the section of this block of code labelled "Err_Handle" and do what it says there instead of crapping out"
Then comes your code.
Then comes that label I mentioned that looks like this:
Code:
Exit_err_handle:
Exit Sub
Err_Handle:
MsgBox Err.Description, vbExclamation, "Error Encountered"
Resume Exit_err_handle
The Err_Handle: is the label that we skip to when we encounter a problem.
The MsgBox pops up a message with a description of what went wrong.
The Resume line tells it where we want to go next. That's just a line of code that says to exit the sub rather than crapping out.
So when you put it all together with the first post, it would look like this:
Code:
Private Sub Form_Timer()
On Error GoTo Err_Handle
If Time >= #9:28:00 AM# And Time <= #4:32:00 PM# Then
CurrentDb.Execute "qryMasterMinuteTrackingHISTORYupdates"
End If
Exit_err_handle:
Exit Sub
Err_Handle:
MsgBox Err.Description, vbExclamation, "Error Encountered"
Resume Exit_err_handle
I hope this makes sense.
Protip: if you get into VBA coding any deeper, especially if you plan to deploy using the runtime, then get into the habit of using this kind of error trapping and you'll be very thankful! Take a few minutes and Google something like "VBA Error handling" and see if you can find some good articles that explain it more comprehensive than I did!
Good luck