Limit on characters in unbound text box

sstasiak

Registered User.
Local time
Today, 13:40
Joined
Feb 8, 2007
Messages
97
What should I set the input mask to if I want to create an unbound text box to only accept exactly 8 alphanumeric characters.?
 
An input mask of AAAAAAAA requires 8 alphanumric characters. As a favor to your users, anytime you use an input mask, you should include code to assure that when the user clicks on the control, the cursor goes to the beginning of the textbox. If you don't do this, a user that types fast will click on the field and start typing, only to find that they've started in the middle of textbox! Then they'll have to go back and start over again!

Code:
Private Sub YourTextBoxName_Click()
    Me.YourTextBoxName.SelStart = 0
End Sub
 
Thanks for the help.

I had the input mask set to "Password" so that the password shows up as *** when it's typed. Can I put code behind that text box so that 8 alphanumeric characters are required AND the **** shows up instead of the actual text?
 
What code are you using to submit the entered password? While you could write code to check the length of the password and check to make sure that all characters fall within 0-9 and A-Z, the simple way to do this would be to pop up a messagebox giving the password format needed if the logon fails!
 
Here's a hack I worked out to assure that:

1) The password is exactly 8 characters long
2) That each character falls between 0-9, A-z and a-z

Substitute the name of your control that holds the password for PWString and the name of your button for submitting the password for SubmissionButton

Code:
Private Sub PWString_LostFocus()
Dim I As Integer
Dim Hits As Integer
Hits = 0

'This insures that the password is 8 characters long
If Len(Me.PWString) <> 8 Then
  MsgBox ("Passwords must be 8 digits long!")
  Me.SubmissionButton.SetFocus
  Me.PWString.SetFocus
  Me.PWString.SelStart = 0
  Me.PWString.SelLength = Len(Me.PWString)
End If

'This insures that all characters are Alpha/Numeric

For I = 1 To Len(Me.PWString.Value)
  ANChar = Mid(Me.PWString, I, 1)
    If ((Asc(ANChar) >= 48 And Asc(ANChar) <= 57)) Or ((Asc(ANChar) >= 65 And Asc(ANChar) <= 90)) Or ((Asc(ANChar) >= 97 And Asc(ANChar) <= 122)) Then
   'Do nothing
   Else: Hits = Hits + 1
 End If
Next I

    If Hits > 0 Then
      MsgBox "All characters must be Letters or Numbers"
      Me.PWSubmissionButton.SetFocus
      Me.PWString.SetFocus
      Me.PWString.SelStart = 0
      Me.PWString.SelLength = Len(Me.PWString)
    End If

End Sub
 

Users who are viewing this thread

Back
Top Bottom