|
-
Jun 28th, 2005, 08:47 AM
#1
Thread Starter
Frenzied Member
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
-
Jun 28th, 2005, 12:27 PM
#2
Frenzied Member
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.
Last edited by salvelinus; Jun 28th, 2005 at 12:30 PM.
Tengo mas preguntas que contestas
-
Jun 28th, 2005, 12:44 PM
#3
Thread Starter
Frenzied Member
Re: How to trap errors in access 2000 forms
 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
-
Jun 29th, 2005, 06:28 AM
#4
Frenzied Member
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.
Tengo mas preguntas que contestas
-
Jun 29th, 2005, 06:47 AM
#5
Thread Starter
Frenzied Member
Re: How to trap errors in access 2000 forms
 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
-
Jun 29th, 2005, 06:56 AM
#6
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.
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
-
Jun 29th, 2005, 07:25 AM
#7
Frenzied Member
Re: How to trap errors in access 2000 forms
The before_update event of the textbox.
Tengo mas preguntas que contestas
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|