Results 1 to 4 of 4
  1. #1
    starlancer805 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jan 2015
    Posts
    5

    Unhappy Error Handeling for a 3201 and 3022 Error

    Hey! Thanks for taking time to read my post!

    I am having a problem on figuring out where to place the error handeling code for a 3201 error (You cannot add or change a record because a related record is required in table '|') and 3022 error (duplicate primary key error) that I am getting. I understand what the error is for and why I am getting it, but I am not sure where to put the code to display a custom message.

    The error happens when a user, who accidentally entered an invalid value, tries to change focus from the subform to the main form with the invalid value still present on the subform. I have an error handeling set up on the 'After update' for the particular field itself, which works great:
    Const errorcode1 As Integer = 3201
    Const errorcode2 As Integer = 3022
    On Error GoTo Skip1
    DoCmd.Requery
    Skip1: If ERR = errorcode1 Then
    MsgBox "You have entered to many numbers into the Request ID field, Or this Request number does not exist."
    Exit Sub

    End If

    If ERR = errorcode2 Then
    MsgBox "The Request you are trying to enter has already been ordered. Please enter a new Request ID into the field."
    Exit Sub

    End If


    However when the user changes focus from the sub form to the main form, again with the invalid value still present, I still get the 3201 and 3022 error (I have tried putting it in the change focus events but it does not seem to work, unless I am putting it in wrong. I have no other code in those events if that makes a difference). I cant figure out where to place the error handeling for this event.

    Thanks for the help and I hope that you have a good day! If you are confused, let me know and I will try to explain it better.

    Starlancer

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Download the free utility MZToolsForVBA

    It will insert general error handling for you at the click of a button, and much more

  3. #3
    starlancer805 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jan 2015
    Posts
    5
    Okay cool thanks! I will look into that!

    However, I think I figured it out for the most part. I did not know about the "Case Select" function, which I put in the OnError event in the subform. Here is the code I have:

    Select Case DataErr
    Case 3201
    MsgBox "This request number does not exist, please change it before continuing."
    Exit Sub

    Case 3022
    MsgBox "The Request you have entered has already been ordered. Please remove this value and enter a new one before proceeding."
    Exit Sub

    Case Else
    MsgBox ("You have encountered an unexpected error. " & DataErr & " Please contact your system administrator.")
    Exit Sub

    End Select


    It still displays the error box after it displays my custom message. Any idea on how to get rid of that?

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    see http://www.techonthenet.com/access/f...anced/case.php

    You should go to the techonthenet site for anything access you don't understand

Please reply to this thread with any new information or opinions.

Similar Threads

  1. The Error 3022 Duplicate Problem
    By boywonder381 in forum Programming
    Replies: 21
    Last Post: 09-01-2014, 11:27 PM
  2. Replies: 3
    Last Post: 01-23-2014, 07:49 AM
  3. Replies: 4
    Last Post: 02-13-2013, 10:46 AM
  4. Error 3201 on Form / Subform
    By jerem in forum Programming
    Replies: 2
    Last Post: 12-01-2012, 12:34 AM
  5. Replies: 0
    Last Post: 07-16-2012, 05:42 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums