data validatie in UserForm


Posted by WangYa on December 20, 2001 7:59 PM

In the old DIALOG forms it was possible to set the datatype allowed for a textbox. How can I do the same in a textbox in a userform? (thus avoiding that people fill in letters instead of numbers).

WangYa



Posted by Colo on December 20, 2001 10:09 PM

Hi. You can use "change events" like this.

Private Sub TextBox1_Change()
'///Please Paste UserForm Module
If IsNumeric(TextBox1.Value) = False Then
Application.EnableEvents = False
MsgBox "Only numbers please!", vbCritical
TextBox1.Value = Left(TextBox1.Value, Len(TextBox1.Value) - 1)
Application.EnableEvents = True
End If
End Sub