How can I make a field of a textbox
only receive integer values?
How can I make a field of a textbox
only receive integer values?
Dim textval As String
Dim numval As String
Private Sub TextBox1_Change()
textval = TextBox1.Text
If IsNumeric(textval) Then
numval = textval
Else
TextBox1.Text = CStr(numval)
End If
End Sub
In event KeyPress
of your TextBox add the following check:
Private Sub TextBox1_KeyPress(KeyAscii As Integer)
if not IsNumeric(Chr$(KeyAscii)) then
KeyAscii= 0
exit sub
end if
End Sub