View Single Post
Old 03-07-2019, 05:11 AM   #1
Newly Registered User
Join Date: Oct 2008
Posts: 1,250
Thanks: 54
Thanked 3 Times in 2 Posts
aman is an unknown quantity at this point
Validation on textbox not to accept any alphabets

Hi guys,

The following code checks if any alphabets are entered in the textbox and display an error message if the user is typing any alphabet. I want to amend this so that no error message displays on the screen but if the user types alphabet then just ignore the alphabet (textbox must not accept any alphabet).

Private Sub txtAccount1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
 If -CLng(Chr(KeyAscii) Like "[0-9]") = 0 Then MsgBox "Please Enter Numbers Only", vbCritical + vbOKOnly, "Account no validation"
    KeyAscii = KeyAscii * -CLng(Chr(KeyAscii) Like "[0-9]")
End Sub
I hope it makes sense. Any help will be much appreciated.


aman is offline   Reply With Quote