As you type the text
Clicking a command button to validateVB Code:
Private Sub Textbox1_KeyPress(index As Integer, KeyAscii As Integer) 'Accepts only numeric input Select Case KeyAscii Case vbKey0 To vbKey9 Case vbKeyBack, vbKeyClear, vbKeyDelete Case vbKeyLeft, vbKeyRight, vbKeyUp, vbKeyDown, vbKeyTab Case Else KeyAscii = 0 Beep End Select End Sub
VB Code:
Private Sub Command1_Click() If Not IsNumeric(Text1.Text) Then MsgBox "Please enter numbers only.", vbInformation 'you may also consider erasing it Text1.Text = "" End If End Sub




Reply With Quote