Results 1 to 9 of 9
  1. #1
    Remster is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    317

    Changing a default error message: "The value you entered isn't valid for this field"

    I want to change the default error message "The value you entered isn't valid for this field" to something that will be intelligible to the user. I've found out from the VBA Help feature how to change default messages ...



    Code:
    Private Sub Form_Error(DataErr As Integer, Response As Integer)
        Const conDuplicateKey = 3022
        Dim strMsg As String
     
        If DataErr = conDuplicateKey Then
            Response = acDataErrContinue
            strMsg = "Each employee record must have a unique " _
                & "employee ID number. Please recheck your data."
            MsgBox strMsg
        End If
    End Sub
    ... but I can't for the life of me work out how to refer to a data type violation. Can anyone help please?

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Have you tried putting a breakpoint in that code to see what DataErr has for a value?

  3. #3
    Remster is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    317
    No, but I've discovered the answer anyway: DataErr = 2113.

    For some reason I seem to be able to find the answers to these problems for myself, but only after I've posted a thread about them!

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    That's great! What method did you use to discover the error number? Posting an issue and then answering your own thread is an excellent way to inform the others that read these forums.

  5. #5
    Remster is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    317
    I just hit on the right Google search at last!

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    So did you end up with a Select Case structure in the Form's Error event or what?

  7. #7
    Remster is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    317
    Assuming I understand what that means (which is doubtful), no. I just got rid of the "Const" line in the code above and replaced "DataErr = conDuplicateKey" with "DataErr = 2113". I've read elsewhere that if you want a different message for each field, you can embed more than one "If ... End If" statement within the main one. Here's what I copied from the website (I'm afraid I didn't make a note of the source):

    Code:
    Private Sub Form_Error(DataErr As Integer, Response As Integer)
    If DataErr = 2113 Then 'Data entered doesn't match datatype 
     
    If Screen.ActiveControl.name = "txtAmount" Then
    Response = MsgBox("Data For Amount Field Must Be Entered in Currency Format!", vbExclamation, "Data is Not in Currency Format")
    Response = acDataErrContinue
    End If
     
    If Screen.ActiveControl.name = "txtDate" Then
    Response = MsgBox("Field Must Be a Valid Date!", vbExclamation, "Data is Not a Valid Date")
    Response = acDataErrContinue
    End If
     
    End If
    End Sub

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    That's great Remster. That is exactly the follow-up readers need who cruise these forums. BTW, here's a *free* utility that I use all of the time that you might like: http://www.oaltd.co.uk/Indenter/

  9. #9
    Remster is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    317
    Thank you.

    For info, I've just found this list of error codes (not comprehensive). The code for a duplicates error is 3022. It seems to work for a multiple-field index too.

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

Similar Threads

  1. What does "not a valid bookmark" mean?
    By ejohnso4 in forum Forms
    Replies: 3
    Last Post: 06-05-2014, 08:49 AM
  2. Replies: 13
    Last Post: 12-05-2011, 05:10 AM
  3. Replies: 12
    Last Post: 06-14-2010, 08:39 PM
  4. Error message and How do I find the "value Field" ?
    By createdwithfire in forum Forms
    Replies: 1
    Last Post: 11-05-2009, 12:26 PM
  5. "Overflow" error message.
    By joeferraro2000 in forum Queries
    Replies: 0
    Last Post: 03-08-2007, 06:36 PM

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