Error Trapping

  • Thread starter Thread starter D B Lawson
  • Start date Start date
D

D B Lawson

Guest
If a user has a problem with a field which has an event procedure attached, is there any way of stopping the system opening up the code to resolve the error? Can you make is do something else instead?
 
You don't say what error is being generated.

In order to trap an error you need to use the On Error statement and also to know what error number is generated. In your event procedure code for the field, type in this code before your other code

On Error GoTo ErrorHandler:

you then will have your existing code and after this code you can then write your error handling code. In order that VB will recognise the ErrorHandler code you need to label this code as in the example below:

Private Sub cmdNew_Click()

On Error GoTo ErrorHandler:
Your Existing code goes in here
Exit sub (This will bypass the error handling code if no errors are generated)
ErrorHandler: (Line label)
Your error handling code goes here
End Sub

What the On Error statement does is that it will re-direct the program to the bit of code that corrects the error or displays messages to the user etc. If there is no error trapping then VB will display its standard error messages.

If you need anymore help then just post again.
 
I have a question for you (or anyone)

the code you suggested above - it works for me in other programs. But one that i am workin on now, none of the [On Error Goto ...] statments work. I keep getting errors that they are not defined, or are not the same name as the event and yet they are!

example:

Private Sub Form_Load ()
On Error GoTo Err_Form_Load

DoCmd.Maximize

Me.EditPage.Enabled = False
Me.TreeView1.Font.Name = "Verdana"
Me.TreeView1.Font.Size = "9"

Exit_Form_Load:
End Sub

Err_Form_Load:
MsgBox Err.Description
Resume Exit_Form_Load

End Sub

like i said this code works in other programs but will not work at all in this one!!! but nothing is different.

any help would be appreciated

- Topher
 
Private Sub Form_Load ()
On Error GoTo Err_Form_Load

DoCmd.Maximize

Me.EditPage.Enabled = False
Me.TreeView1.Font.Name = "Verdana"
Me.TreeView1.Font.Size = "9"

Exit_Form_Load:
End Sub <-------------Should be Exit Sub

Err_Form_Load:
MsgBox Err.Description
Resume Exit_Form_Load

End Sub
 

Users who are viewing this thread

Back
Top Bottom