Numbers Only Textbox
Dear Programmers
I want to make a routine named “NumberOnly”
Private Sub TextBox4_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox4.KeyPress
‘Here I want to call the function as
Numbersonly
End sub
All textboxes must accept numbers data on which I call this routine
Supose I call this routine on keypress event of textbox4 then textbox4 must accept only numbers only.
I got these codes from somewhere but it has paremeter error
Private Sub TextBox3_Change()
OnlyNumbers
End Sub
Private Sub OnlyNumbers()
If TypeName(Me.ActiveControl) = "TextBox" Then
With Me.ActiveControl
If Not IsNumeric(.Value) And .Value <> vbNullString Then
MsgBox "Sorry, only numbers allowed"
.Value = vbNullString
End If
End With
End If
End Sub
Please help