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

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
 
R

Rick Brandt

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top