Results 1 to 7 of 7

Thread: How to trap errors in access 2000 forms

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Arrow 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

  2. #2
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    Re: How to trap errors in access 2000 forms

    VB Code:
    1. Private Sub Yada()
    2.    On Error GoTo errYada
    3.    '
    4.    ' bunch of code
    5.    '
    6.    Exit Sub
    7.  
    8. errYada:
    9.    ' error handling code
    10.    Select Case Err.Number
    11.       Case 123
    12.          ' do something
    13.          Resume   'start at line that threw error
    14.       Case 456
    15.          ' do something else
    16.          Resume Next  'start at line following error
    17.       '..
    18.       '..
    19.       'etc
    20.       Case Else
    21.          MsgBox Err.Number & vbcrlf & Err.Description, , "Unhandled Error"
    22.    End Select
    23. 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

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Lightbulb Re: How to trap errors in access 2000 forms

    Quote Originally Posted by salvelinus
    VB Code:
    1. Private Sub Yada()
    2.    On Error GoTo errYada
    3.    '
    4.    ' bunch of code
    5.    '
    6.    Exit Sub
    7.  
    8. errYada:
    9.    ' error handling code
    10.    Select Case Err.Number
    11.       Case 123
    12.          ' do something
    13.          Resume   'start at line that threw error
    14.       Case 456
    15.          ' do something else
    16.          Resume Next  'start at line following error
    17.       '..
    18.       '..
    19.       'etc
    20.       Case Else
    21.          MsgBox Err.Number & vbcrlf & Err.Description, , "Unhandled Error"
    22.    End Select
    23. 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

  4. #4
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    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

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Arrow 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

  6. #6
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    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.

    BOFH Now, BOFH Past, Information on duplicates

    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...

  7. #7
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    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
  •  



Click Here to Expand Forum to Full Width