Exclude a character from a field

E

Eric

I would like to exclude the use of the letter "O" in a field, I want
to be able to any other number or letter in this field. Either by
using a controll in the text box properties or in the table setup.
Might need to use a macro but Im at lose here. Might need to a module?
I just can't think it through. Any help would be appreciated. - Eric
 
A

Allen Browne

1. Open the form in design view.

2. Right-click the text box to limit, and choose Properties.

3. On the Event tab of the properties box, set the On Key Press property to:
[Event Procedure]

4. Click the Build button (...) beside this. Access opens the code window.

5. Add these 3 lines between the "Private Sub..." and "End Sub" lines:

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 79 Or KeyAscii = 111 Then
KeyAscii = 0
End If
End Sub

Explanation: the value of KeyAscii indicates the character that was pressed.
79 is upper case O, and 111 is lower case o. In either of these cases, the
code sets the value of KeyAscii to zero, which effectively destroys the
keystroke before it is processed.
 
J

jacob

Try set the field valdation rule to Not "O" in the table
properties. If that doesn't work, try setting the
control validation property to Not "O" in the form
control properties.
Good luck
 

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