Force only allows characters (In Textbox)

This code forces only allows ASCII characters into a textbox

Select Case KeyAscii Case 8 'backspace Case 46 'full stop Case 48 To 57 'range of numbers Case Else MsgBox "Please enter only numbers" KeyAscii = 0 End Select

You can also use the following code to do the same

Private Sub txtpnum_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) 'Ensure only number and no spaces are entered into this box If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 Then MsgBox "Please enter the personel number with no spaces, check digit or -", vbExclamation + vbOKOnly, "Input Error" KeyAscii = 0 End If End Sub

Here is the ASCII Codes that can be used



Code Snippits