Set rules for what can be entered into a box?

JillWelch

Registered User.
Local time
Yesterday, 23:54
Joined
Oct 31, 2002
Messages
18
I have a form that I can enter addresses into, what I would like to do is make sure that in the State/Province box that only two letters can be entered, and I also want it to automatically capitalize the two letters.

I need to eliminate typos in this box because l will be using this data later to make an address list of all contributors and don't want to end up with a bunch of different-looking envelopes.

Thanks for your help!

Jill
 
Code to only allow letters, and it capitalizes on keystroke.

Code:
Private Sub txtField_KeyPress(KeyAscii As Integer)
On Error Resume Next
    
    Select Case True
        Case KeyAscii = 8  'Backspace
        Case KeyAscii = 13 'Return Key
        'Case KeyAscii >= 48 And KeyAscii <= 57 'Numbers
        Case KeyAscii >= 65 And KeyAscii <= 90  'Upper Case letters
        Case KeyAscii >= 97 And KeyAscii <= 122 'Lower Case letters
            KeyAscii = Asc(UCase(Chr(KeyAscii)))
        Case Else
            KeyAscii = 0
    End Select

End Sub

As for limiting the field to only two characters, if you set the field size in the table to 2 then it wont let you enter more then that (on a Bound Control that is)
 
Thank you!!

One more question, where do I enter this code?
 
Another approach is to use a combo box which is linked to a table of authorized state or province abreviations. If you make the combo box "limit to list," users may only enter those you determine are correct. If you make that list upper-case only, the combo box will replace the upper-case version (from your list) for any variation which the user might enter.

1. Create a table with one text field, two characters long.
2. Open the table and enter the abreviations you will accept.

3. With the control wizard activated, create the combo box on your form, telling the wizard to use that table you just made for the source.

It's done!

-Curt
 
The State/Province box KeyPress Event
 

Users who are viewing this thread

Back
Top Bottom