Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2005

    Unanswered: Length of a numeric text box

    I have a text box named "Account Number" and I want it to hold only a 9 digit number. No more and No less than 9 numbers. If it is not 9 numbers, I want a msg box to alert the user that they need to endter 9 characters.

    Can anyone help me with the code and let me know what event procedure it should be entered under.

    Thanks for the help.


  2. #2
    Join Date
    Nov 2003
    The first thing you may want to consider is the Input Mask property (see Access Help). Real basic... you can ensure that in fact no more than 9 digits will be entered into the TextBox by simply placing this into the Input Mask Property: #########

    In any case, to inform the user that the input provided is incorrect, you will want to place some code into the Before Update event for your TextBox. Your event procedure should look something like this:
    Private Sub mytextBoxName_BeforeUpdate(Cancel As Integer)
      If Len(Me.mytextBoxName) <> 9 Then
        MsgBox "You have entered a incorrect Account Number." & vbCrLf & _
            "Account Numbers must no less than and no more " & vbCrLf & _
            "than 9 digits long.", vbExclamation, "Incorrect Account Number"
        Cancel = True
      End If
    End Sub
    The user is always focused back into the TextBox if the wrong entry (less than or greater than 9 digits) is made. The Cancel = True does this.

    Self Taught In ALL Environments.....And It Shows!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts