• InputMask Message??? (Access 97)

    Author
    Topic
    #372190

    Question 1: I am using an input mask to make sure that the correct format is used in a textbox. When there is an error, the message box that comes up shows what the input mask is and that what was typed is wrong. Is there a way to change what is in this message box?

    Viewing 0 reply threads
    Author
    Replies
    • #594169

      You can use the OnError event of the form to handle errors. An input mask error has error number 2279.

      In design view of the form, make sure the form itself is selected.
      In the Properties window, select the Events tab.
      Near the end of the list, you’ll find the Error event.
      Use it to create an error handler and enter the following code:

      Private Sub Form_Error(DataErr As Integer, Response As Integer)
      Select Case DataErr
      Case 2279
      ‘ Input mask error – display our own error message
      MsgBox “Correct your entry or else…”, vbExclamation
      ‘ And tell Access not to display its own message
      Response = acDataErrContinue
      ‘ Add other special cases here
      ‘…
      ‘ Otherwise, display standard error message
      Case Else
      Response = acDataErrDisplay
      End Select
      End Sub

      • #594172

        Hi Hans

        How can you trap date/time inputMask errors?

        Thanks, John

        • #594176

          Hello John,

          In my Access 97, the routine I posted before traps date/time input masks too. Is that different in later versions?

          If you want to provide detailed information to the user on why the entry is not valid, you can analyse ActiveControl.Text.

          • #594458

            Hi Hans

            I was missing err 2113, following is your of several weeks ago with 2113 added, works great.

            Thank, John

            Private Sub Form_Error(DataErr As Integer, Response As Integer)

            Const INPUTMASK_VIOLATION = 2279 ‘ permit no, phone, ss no,
            Const FIELD_VIOLATION = 2113 ‘ date and time
            Dim Msg As String
            If DataErr = INPUTMASK_VIOLATION Or DataErr = FIELD_VIOLATION Then
            Select Case Screen.ActiveControl.Name

            Case “strPermitNo”
            Beep
            MsgBox “The Registration Number you entered is invalid!” _
            & vbLf & vbLf & vbCr & _
            “Enter it properly as follows:” _
            & vbLf & vbLf & vbCr & _
            ” 2002-00001″ & vbLf & vbCr & _
            ” ^ ^” & vbLf & vbCr & _
            ” | |” & vbLf & vbCr & _
            ” | —– Record Number (5 digits)” & vbLf & vbCr & _
            ” | ” & vbLf & vbCr & _
            ” —– Year (4 digits)” & vbLf & vbLf & vbCr & _
            “Press Esc Key to twice to restore the original field value.”

            Case “strPhone”, “strHomePhone”, “strWorkPhone”, “strBuilderPhone”, _
            “strBuilderCellPhone”
            Beep
            MsgBox “The Phone Number you entered is invalid!” _
            & vbLf & vbLf & vbCr & _
            “Either enter it properly as follows, or leave it blank.” _
            & vbLf & vbLf & vbCr & _
            ” (716) 754-8797″ _
            & vbLf & vbCr & _
            ” ( ) 754-8797 (space bar 3 times to bypass area code)” _
            & vbLf & vbLf & vbCr & _
            “Press Esc Key to twice to restore the original field value.”

            Case “dtmInspectionTime”
            Beep
            MsgBox “The Time you entered is invalid!” _
            & vbLf & vbLf & vbCr & _
            “Enter it properly as follows:” _
            & vbLf & vbLf & vbCr & _
            ” hh:mm ” & vbLf & vbCr & _
            ” hh:mma” & vbLf & vbCr & _
            ” hh:mmp” & vbLf & vbLf & vbCr & _
            “Press Esc Key to twice to restore the original field value.”

            Case “dtmReceiveDate”, “dtmIssueDate”, “dtmExpireDate”, _
            “dtmCORenewalDate”, “dtmTmpCOExpDate”, “dtmInsExpDate”
            Beep
            MsgBox “The Date you entered is invalid!” _
            & vbLf & vbLf & vbCr & _
            “Enter it properly as follows:” _
            & vbLf & vbLf & vbCr & _
            ” m/d/y ” & vbLf & vbCr & _
            ” mm/dd/yy” & vbLf & vbCr & _
            ” mm/dd/yyyy” & vbLf & vbLf & vbCr & _
            “Press Esc Key to twice to restore the original field value.”

            Case Else
            Beep
            Msg = “An input mask violation occurred in control ”
            MsgBox Msg & Screen.ActiveControl.Name & “!”
            End Select
            Response = acDataErrContinue
            End If

            End Sub

      • #594201

        Thanks for the help….another question….is there somewhere that lists all the errors and the associated code? Also if you have more than one text box and they all have a different input mask, is there a way to set a message specifically for each one?

        • #594214

          Try “Error Codes” in the help file in Access 97. Copy the code to a module and run it. The code will create a table “AccessAndJetErrors.” The table will contain two fields, Error Code, and ErrorString, which is the description of the error code.

        • #594378

          Accdb already answered your first question.

          About the second one (specific error messages): when the error occurs, the offending text box is the ActiveControl. You can use the properties of this control (Name, InputMask, ControlSource, …) to create a specific message. Here is an example. Of course, the possible variations are endless.

          Private Sub Form_Error(DataErr As Integer, Response As Integer)
          Dim strMessage As String
          Select Case DataErr
          Case 2279
          Select Case ActiveControl
          Case txtTextEntry1, txtTextEntry2
          strMessage = “Please enter an alphabetic string of exactly 5 characters.”
          Case txtNumericEntry1
          strMessage = “Please conform to the input mask ” & ActiveControl.InputMask
          Case txtNumericEntry2
          strMessage = “This is not a valid entry for ” & ActiveControl.ControlSource
          End Select
          MsgBox strMessage, vbExclamation
          Response = acDataErrContinue
          Case Else
          Response = acDataErrDisplay
          End Select
          End Sub

    Viewing 0 reply threads
    Reply To: InputMask Message??? (Access 97)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: