'on error' question

  • Thread starter somanybugssolittletimetofixthem
  • Start date
S

somanybugssolittletimetofixthem

Can I do the following:

On Error Goto A
.... statement1 ...
On Error Resume Next
.... statement2 ...
On Error Goto 0
.... statement3 ...

I want statement 1 to be caught by the first on error
I want statement 2 never to generate an on error
I want statement 3 to be caught by the first on error
 
M

Marshall Barton

somanybugssolittletimetofixthem said:
Can I do the following:

On Error Goto A
... statement1 ...
On Error Resume Next
... statement2 ...
On Error Goto 0
... statement3 ...

I want statement 1 to be caught by the first on error
I want statement 2 never to generate an on error
I want statement 3 to be caught by the first on error


Yes, that is certainly a legal sequence.

Be aware that On Error GoTo 0 tells Access to process any
errors, not your own error handling code.
 
G

Graham R Seach

You'll love DotNet!

You can't do what you're trying to, in Access. You need to use a single On
Error Goto construct, and then test for the specific error you're looking
for.
Public Sub myProcedure()
On Error Goto Proc_Err

'Your program code goes here

Proc_Exit:
Exit Sub

Proc_Err:
Select Case Err.Number
Case 6 'Overflow
'Handle this error
Case 11 'Divide by Zero
'Handle this error
Case Else
'Handle all other errors
End Select

Resume Proc_Exit
End Sub

Having said that, you can change your error handling at various stages
throughout your program code.

Public Sub myProcedure()
On Error Goto Proc_Err
'Your program code goes here
On Error Goto Proc_Err2
'Your program code goes here
On Error Resume Next
'Your program code goes here
On Error Goto 0
'Your program code goes here

Proc_Exit:
Exit Sub

Proc_Err:
'Handle errors
Resume Proc_Exit

Proc_Err2:
'Handle errors differently
Resume 'At the same line that caused the error
End Sub

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia

Microsoft Access 2003 VBA Programmer's Reference
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0764559036.html
 

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