I want to prevent a user entering a decimal in a text box using the keypress event. For example, he enters 123. and then a message box says no decimals allowed. When the message box is closed I only want 123 remaining in the text box. I have tried several solutions but the decimal never goes away. I can probably make it work in the lostfocus event but I want the msgbox to appear when the "." is pressed. I don't mind if the text box is even totally cleared.
Here is the code representing several scenarios:
Sub txtAngDist_KeyPress (key)
If key = "." Then
Msgbox("Whole numbers only (no decimals) during the evaluation")
txtangdist.Text = "" 'doesn't clear the "." but don't know why
txtangdist.text=strreplace(txtangdist.text,".","") ' doesn't work
txtangdist.text= txtangdist.Text & "." 'otherwise the strlength stops at the "."
len=StrLength(txtangdist.Text )
txtangdist.Text =StrRemove(txtangdist.Text ,len-1,1) 'doesn't work
End If
End Sub
I tried several other combinations but still can't solve it. It's probably a very simple solution and I will feel like an idiot when I am shown but it won't be the first time. Thanks for your help.
Jim Schuchert