Limit control entry

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I need to place a limit on the number of digits a user can enter into one of
my controls on the form.I need the limit to be nine digits and i would like
to know if this can be done in the form instead of the tables?The users are
creating errors by typing just a few digits more and this is causing report
problems.....please advise...thanks.
 
Set the Validation Rule of the text box on your form to:
< 1000000000

If you prefer, you could use the KeyPress event to check the Len() of the
Text property of the control, and set the KeyAscii to zero of you already
have 9 digits.
 
Thanks Allen,

I used the validation rule on my control as you have provided but i can
still type more than nine digits in this field.Does this have to be done
using code??Please advise on what i could be doing wrong......thanks for your
support on this.
 
So you want the other alternative?

This allows nothing but up to 9 digits (no dec point, no negative). Assumes
text box named Text0.

Private Sub Text0_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case vbKeyBack
'do nothing: backspace always allowed.
Case vbKey0 To vbKey9
'Allowed unless already 9 chars.
If Len(Me.Text0.Text) >= 9 Then
KeyAscii = 0
End If
Case Else
'Destroy any other keystroke.
KeyAscii = 0
End Select
End Sub
 
Back
Top