>I have three textboxes. The user can insert his/her birthday.
>Textbox 1 for day
>Textbox 2 for month
>Textbox 3 for year
>
>I've set the dataformat NUMBER for each textbox. Yet still the
>user can insert all characters. Is there a way to control this
>input so only numbers are allowed ?
The DataFormat property is only good when controls are bounded.
To only accept numeric values in text box use this:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If (Chr$(KeyAscii) >= "0" And Chr$(KeyAscii) <= "9") Or _
KeyAscii = vbKeyBack _
Then
'Do nothing
Else
KeyAscii = 0
End If
End Sub
Éric Moreau, MCPD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Moer inc.
http://www.emoreau.com