How to trap errors in access 2000 forms
Hi guys . i wonder how i can trap the following errors in access 2000 forms.
I have the database tables in sql server 2000 and front end is made by access 2000
forms. I be happy if some one show me how i can trap these errors and promt aproperte message
to the user when they violate them using forms.Thanks
1)Violation of not null constraint
2)primary key violation
3)Trigger violation
4)and other erros
Re: How to trap errors in access 2000 forms
VB Code:
Private Sub Yada()
On Error GoTo errYada
'
' bunch of code
'
Exit Sub
errYada:
' error handling code
Select Case Err.Number
Case 123
' do something
Resume 'start at line that threw error
Case 456
' do something else
Resume Next 'start at line following error
'..
'..
'etc
Case Else
MsgBox Err.Number & vbcrlf & Err.Description, , "Unhandled Error"
End Select
End Sub
The tricky part is figuring out what error number you want to catch. You can deliberately cause one to find it, or check MSDN.
Re: How to trap errors in access 2000 forms
Quote:
Originally Posted by salvelinus
VB Code:
Private Sub Yada()
On Error GoTo errYada
'
' bunch of code
'
Exit Sub
errYada:
' error handling code
Select Case Err.Number
Case 123
' do something
Resume 'start at line that threw error
Case 456
' do something else
Resume Next 'start at line following error
'..
'..
'etc
Case Else
MsgBox Err.Number & vbcrlf & Err.Description, , "Unhandled Error"
End Select
End Sub
The tricky part is figuring out what error number you want to catch. You can deliberately cause one to find it, or check MSDN.
Thank u for u reply. if i want to use your above code where should i put it in my form so it catches the error and prompts the user about the error. for example i got a couple bounded forms that it has couple text boxes. where should i put this codes so it catches the errors for those text boxes. thanks
Re: How to trap errors in access 2000 forms
Depends on your app. Does the user click a button? Put it in the button click event. When the form opens? Put it in the form open event. After the user types something in? AfterUpdate event. Etc.
Re: How to trap errors in access 2000 forms
Quote:
Originally Posted by salvelinus
Depends on your app. Does the user click a button? Put it in the button click event. When the form opens? Put it in the form open event. After the user types something in? AfterUpdate event. Etc.
Many thanks to u reply. Well my form opens in edit mode and user make some selection from combo box in the main form and then then the user has to make selection for 2 other combo box in sub form and type a float value in one text box . I want the error handling fires when the user makes incorect input to this text box. Therefore do u mean i should place your code in Form_error or AfteUpdate event ? or AfterUpdate event of main form or subform ? Thanks
This is a picture of my form :
http://i5.photobucket.com/albums/y18...blesubform.jpg
Re: How to trap errors in access 2000 forms
If the form is bound, then you need it in the before_update event.
If it is unbound, you need it in the validation code before you save the record.
Re: How to trap errors in access 2000 forms
The before_update event of the textbox.