Re: Numbers Only and - Only
The Ascii value for the minus sign is 45.
Re: Numbers Only and - Only
put it on keypress event
Const key = "1234567890"
If KeyAscii <> 0 Then
If InStr(key, Chr(KeyAscii)) = 0 Then
KeyAscii = 0
End If
End If
Re: Numbers Only and - Only
Per Markt....example
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case vbKey0 To vbKey9
Case 45
Case vbKeyBack, vbKeyClear, vbKeyDelete ', vbKeySubtract---remove
Case vbKeyLeft, vbKeyRight, vbKeyUp, vbKeyDown, vbKeyTab
Case Else
KeyAscii = 0
Beep
End Select
End Sub
EDIT: FYI, vbKeySubtract is applicable in either KeyDown or KeyUp events but not
on a KeyPress event.
Re: Numbers Only and - Only
..... and never forget, that in cases like this, a user still can copy&paste whatever characters he wishes into the Textbox......
How about trapping the CTRL+V-Combination?
Re: Numbers Only and - Only
@zoni
How do you trap ctrl v
@Samoscarbrown
I will give that a try later thanks
Re: Numbers Only and - Only
Re: Numbers Only and - Only