K
Katherine
I have a textbox in my userform for a price to be entered. Because of the way
we intend to use the information, the price needs to be purely numeric - no
pound signs and no commas or full stops.
Somebody on the boards helped me out with the following piece of code, which
throws up a messagebox if the user tries to put text in the textbox, but I
also need to somehow prevent them from entering commas or pound signs.
Because I don't really understand exactly what this code is doing (what's
the CLng bit all about?), I have no idea how to tweak it into doing what I
want. Can anyone provide any suggestions?
Private Sub txtPrice3_exit(ByVal cancel As MSForms.ReturnBoolean)
Dim x As Long
On Error GoTo Invalid
If txtPrice3.Text = "" Then Exit Sub
x = CLng(txtPrice3.Text)
Exit Sub
Invalid:
MsgBox "Price must be a number." & vbCrLf & vbCrLf & _
"Please don't use any pound signs (£) or other punctuation.", _
vbExclamation, "Invalid Price!"
txtPrice3 = Null
cancel = True
End Sub
we intend to use the information, the price needs to be purely numeric - no
pound signs and no commas or full stops.
Somebody on the boards helped me out with the following piece of code, which
throws up a messagebox if the user tries to put text in the textbox, but I
also need to somehow prevent them from entering commas or pound signs.
Because I don't really understand exactly what this code is doing (what's
the CLng bit all about?), I have no idea how to tweak it into doing what I
want. Can anyone provide any suggestions?
Private Sub txtPrice3_exit(ByVal cancel As MSForms.ReturnBoolean)
Dim x As Long
On Error GoTo Invalid
If txtPrice3.Text = "" Then Exit Sub
x = CLng(txtPrice3.Text)
Exit Sub
Invalid:
MsgBox "Price must be a number." & vbCrLf & vbCrLf & _
"Please don't use any pound signs (£) or other punctuation.", _
vbExclamation, "Invalid Price!"
txtPrice3 = Null
cancel = True
End Sub