Data Validation Text Box

  • Thread starter jserrone via AccessMonster.com
  • Start date
J

jserrone via AccessMonster.com

Hello,
I have a simple text box and I would like to restrict a user to key in
something with an A followed by 6 digits. Similar to this A555555 so that if
the user keys in 555555 or P555555 it will receive an error message. I know
if VBA I can restrict a user to enter numbers only by doing the following on
the Key Press event but don't know how to incorporate the first digit as a
Letter.

Private Sub Text1_KeyPress(KeyAscii As Integer)
'check if value is numeric
If Not IsNumeric(Chr(KeyAscii)) Then
'allow backspace and enter keys only
If Not (KeyAscii = 8 Or KeyAscii = 13) Then
KeyAscii = 0
End If
End If
End Sub
 
D

Dirk Goldgar

jserrone via AccessMonster.com said:
Hello,
I have a simple text box and I would like to restrict a user to key in
something with an A followed by 6 digits. Similar to this A555555 so that
if
the user keys in 555555 or P555555 it will receive an error message. I
know
if VBA I can restrict a user to enter numbers only by doing the following
on
the Key Press event but don't know how to incorporate the first digit as a
Letter.

Private Sub Text1_KeyPress(KeyAscii As Integer)
'check if value is numeric
If Not IsNumeric(Chr(KeyAscii)) Then
'allow backspace and enter keys only
If Not (KeyAscii = 8 Or KeyAscii = 13) Then
KeyAscii = 0
End If
End If
End Sub


The "A" is redundant, apparently, so you might consider having them just
enter the 6 digits. However, to get what you've asked for, you could set
the Validation Rule property of the text box to

Like "A######"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top