Results 1 to 11 of 11
  1. #1
    thekruser is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    93

    Custom error message problem

    I am trying to create a custom error message. I am getting a very odd responce. On error, I get an Access-generated Runtime error '3022'. If I hit End then try to close the form, I get my custom error message.



    The first text box on the form is for Employee ID. After update, it should be validated and if duplicate, show the custom error message. The Access message should not show at all. Can someone please have a look at this an help me understand where I am going wrong?

    Thanks in advance for your time and help. Have a good day!

    Here is what I have:

    Code:
    Option Compare Database
    Private Sub Form_Error(DataErr As Integer, Response As Integer)
    Const conErrDuplicateKey = 3022
    Select Case DataErr
       Case conErrDuplicateKey
          MsgBox "The Employee Number you entered already exists."
          Response = acDataErrContinue
       Case Else
          ' It's an unexpected error.  Let Access handle it.
           Response = acDataErrDisplay
    End Select
    End Sub
     
    Private Sub cmdContinue_Click()
    Dim rs As Object
    Dim lngBookmark As String
        'set a variable to the current record
        lngBookmark = Me.EmployeeID
        
        'open the new form
        DoCmd.OpenForm "frmIndividualDataEdit"
        'take it to the selected record
        Set rs = Forms!frmIndividualDataEdit.RecordsetClone
        rs.FindFirst "EmployeeID = '" & lngBookmark & "'"
        Forms!frmIndividualDataEdit.Bookmark = rs.Bookmark
        Set rs = Nothing
        DoCmd.Close acForm, "frmAddNewJoin"
        
    End Sub
     
    Private Sub EmployeeID_AfterUpdate()
        If Me.Dirty Then Me.Dirty = False
    End Sub

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    You may be getting the runtime error message if you have "Break on all errors" enabled. Check the TOOLS > OPTIONS menu in the VBE and see if that is checked (check box).

    If it is, error handlers are irrelevant in procedures because Access will error out if an error is encountered.

  3. #3
    thekruser is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    93
    @ajetrumpet

    Thank you for the reply. I checked and it is an option group not a check box. My options are:

    'Break on All Errors'
    'Break in Class Module'
    'Break on Unhandled Errors' (selected)

    Is that right?

  4. #4
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    yes that is right. BREAK ON ALL ERRORS in what you want unchecked. If it's checked, that's the primary issue. I believe the "break on unhandled" means that the VBE will check for an "On Error" statement present in each procedure at runtime.

  5. #5
    thekruser is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    93
    Tried all three options. Same result on all tries. Back to square one...

  6. #6
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by thekruser View Post
    Tried all three options. Same result on all tries. Back to square one...
    if you upload the file, I'm sure I'll have time to look at it. others might to.

  7. #7
    thekruser is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    93
    Here it is. Thank you for your time and help.

  8. #8
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by thekruser View Post
    Here it is. Thank you for your time and help.
    please tell us what exactly to look for and what to do to duplicate the error.

  9. #9
    thekruser is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    93
    Open frmAddNew and enter an EmployeeID that exists. You get a runtime error. The custome error message only shows after you close the Access error and try to close the form.

  10. #10
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    kruser,

    I forgot about this thread....sorry about that. I've been busy with a few things. I realized I forgot when I saw this: http://www.access-programmers.co.uk/...d.php?t=199552

    If you do get a response over there please let people know here. I'll try and look at your file tomorrow sometime if I get a chance...unless someone else takes a peek first.

  11. #11
    thekruser is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    93
    Sorry it took so long for me to respond. I did get an aswer there. I do not have access to it here...damn IT policies. Either way, the answer is still on that link.

    Thanks for your reply!!

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

Similar Threads

  1. error message
    By ngeng4 in forum Forms
    Replies: 85
    Last Post: 03-25-2010, 06:47 AM
  2. Custom Query Parameter Prompts-- Problem
    By tylerthompson in forum Forms
    Replies: 11
    Last Post: 07-07-2009, 10:28 PM
  3. where do i start with this error message?
    By Student4Life in forum Access
    Replies: 0
    Last Post: 01-09-2009, 04:12 PM
  4. If / Then Error Message
    By Schwagr in forum Forms
    Replies: 4
    Last Post: 03-30-2006, 06:28 AM
  5. Creating a *Good* Custom Message Box
    By Jerimiah33 in forum Forms
    Replies: 1
    Last Post: 11-09-2005, 04:47 PM

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