Exclude a character from a field

  • Thread starter Thread starter Eric
  • Start date Start date
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
 
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.
 
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
 
Back
Top