how to force user not to enter "%" sign into a TextBox.

  • Thread starter Thread starter mezzanine1974
  • Start date Start date
M

mezzanine1974

I need to force user not to enter "%" sign into a text box. OnExit
event of text box, which code sould i use, so that I will make the
CANCEL=True?
I can do that by placing ComboBox and defining a criteria on the query
where combobox is bounded. But i want to learn how to do in VBA.
There are lots of information about it on this group but i failed to
understand.
Thanks
 
mezzanine1974 said:
I need to force user not to enter "%" sign into a text box. OnExit
event of text box, which code sould i use, so that I will make the
CANCEL=True?
I can do that by placing ComboBox and defining a criteria on the query
where combobox is bounded. But i want to learn how to do in VBA.
There are lots of information about it on this group but i failed to
understand.
Thanks

Use BeforeUpdate...


If Instr(1, Me.TextBoxName, "%") Then
MsgBox "No % characters allowed"
Cancel = True
End If

You can also use the KeyPress event and reject that character...

If KeyAscii = 37 Then KeyAscii = 0

You would still want the BeforeUpdate code in case they paste the character in
from the clipboard.
 
Back
Top