How can I require all-caps in a form field?

T

Theber

I want users to enter the data in one field of my form in all caps. I can't
use a drop-down list, and don't think I can use an input mask as I don't know
anything about what the data will look like (how many characters, words,
punctuation, etc). I didn't see a relevant option on the properties for the
text box. Do I have to control it from the underlying table?

Basically, I'd like it to default to caps so that the user doesn't have to
think about it. Is this possible?

Thanks!
 
D

Douglas J. Steele

In the AfterUpdate event of the control, use the UCase function to convert
the input to upper case:

Private Sub MyTextbox_AfterUpdate()

Me.MyTextbox = UCase(Me.MyTextbox)

End Sub
 
B

BruceM

You could just set the format of the text box to >. That is, enter a
Greater Than sign in the text box Format property. Let the users type using
whatever format they choose; it will display as all caps.
You would have to apply the same format whenever you want the data
displayed.
You could also convert the text using the UCase function. In the text box
After Update event:
Me.YourField = UCase(Me.YourField)
 
S

Stockwell43

Hi Theber,

If I understand you correctly, open your fields properties menu and place a
right arrow > , in the format line. When the user types it will show lower
case but when they exit the field it will show everything in caps.
 
A

Allen Browne

Bruce, I wonder if you realize that doesn't actually change the case?
It only affects the way Access displays it. Do a merge to Word (for
example), and you see the uncased data.

There are a couple of other side effects to doing this also:
- It truncates the display of memo fields.
- There were bugs in A2003 SP3 where you got nothing displayed in a combo if
the field had this format.
 
S

Stockwell43

Sorry Theber,

Place this code in the On KeyPress event of you textbox where you want the
caps.

Place this code under it just below the black line to separate it.
Private Sub ChangetoUpperCase(KeyAscii As Integer)
If KeyAscii >= 97 And KeyAscii <= 122 Then
KeyAscii = (KeyAscii - 32)
End If
End Sub

I have in a working database and it will produce caps as you start typing
and will show on reports. See how it works out for you.
 
B

BruceM

Thanks for the observations, Allen. If you are talking about the text box
format, I realize it changes only the way the text is displayed. I have
seen indecipherable chemical formulas and other puzzlements as a result of
using all upper case, so I am reluctant to convert data. However, since the
OP specifically mentioned forcing upper case I should probably have just
left out the formatting option. I did not know about the combo box bugs,
nor about the truncated memo fields.
 

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