Retry in error handler

  • Thread starter karen s via AccessMonster.com
  • Start date
K

karen s via AccessMonster.com

I have a scheduled windows job that opens an accessmdb and executes a
procedure that transfers AS400 data then runs various queries to prepare the
data. My problem is when there are AS400 timeouts I get a timeout error and
my app stops. I need to implement a good error handler including a retry
loop so that if there are timeouts, my app can wait for some time and try
again. Has anyone done something similar. I am new to coding in VBA and
realize that I have a lot to learn about coding. I know what I want, but how
to do it is the problem.

Thanks,
Karen
 
B

Brendan Reynolds

Public Sub RetryOnError()

Dim x As Long
Dim lngRetries As Long
Dim lngWait As Long
Dim lngLoop As Long

On Error GoTo ErrorHandler
x = 100 / 0

ExitProcedure:
Exit Sub

ErrorHandler:
If lngRetries < 3 Then
lngWait = Int((1000000) * Rnd)
For lngLoop = 0 To lngWait
'do nothing
Next lngLoop
lngRetries = lngRetries + 1
Resume
Else
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbOKOnly Or vbInformation, "I Give Up!"
Resume ExitProcedure
End If

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top