form vb - error message -- validation

  • Thread starter Thread starter Nilz-p
  • Start date Start date
N

Nilz-p

i need some error maeages with a validation for my text boxes on vb ..
sort me out


stuff like

no numbers alowed
no text alowed

lets say i have a text box thats ment to have a phone number on it. i
i type in a letter .. an errer message should apear ( numbers only)

i want the same for a text box with a "name"... error meeage (n
numbers and spaces alowed"

send me a sample code for that kind of stuff please...
than
 
Here are two routines

Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Select Case KeyAscii
Case 48 To 57:
Case Else:
MsgBox "No text allowed"
KeyAscii = 0
End Select
End Sub

The name one I have allowed hyphen and dot as well (for hyphenated names,
and Jr. etc.)

Private Sub TextBox2_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Select Case KeyAscii
Case 32, 45, 46: 'space, - & .
Case 65 To 90: 'A-Z
Case 97 To 122: 'a-z
Case Else:
MsgBox "No numbers allowed"
KeyAscii = 0
End Select
End Sub


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 

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

Back
Top