Minding said:
I'm using Access 2002 and Jennings' book, Using ....
I want to force all caps to be stored in the first and lastname
fields of my Author table -- and also allow for hyphens in the
lastname field. I've tried using a combination of symbols from
Jennings' table in the Input Mask and Format Field Properties. I
thought I got it working in my Author table (only caps displayed),
but when I LookUp the Author name not in the Audio Collection table
(created using the Data Type LookUp Wizard), the names are not
capitalized. The same thing in any form I create.
I'm sure I'm missing something obvious, but can't figure it out.
Thanks for any help.
The Format property only governs the way text is displayed, not how it
is stored. There are several ways to approach this problem:
1. Use an input mask, beginning it with the character '>'.
The drawback to this approach is that you have to specify a mask
character for each character that might be entered in the field. A mask
of ">C" allows at most 1 character to be entered. A mask of
">CCCCCCCCCC" allows up to 10. Specifying fixed-length input masks is a
pain for relatively free-form data like names.
2. Convert the text in the field to upper case immediately after it has
been entered. For this you can use the control's AfterUpdate event,
with an event procedure like this:
'----- start of example code -----
Private Sub LastName_AfterUpdate()
With Me.LastName
.Value = UCase(.Value)
End With
End Sub
'----- end of example code -----
The only disadvantage of this approach that I can think of is that
the user doesn't see the upper-case letters while typing. I still favor
this approach, when it's necessary for a field to be upper case.
3. Convert the letter keystrokes to upper case as they are typed. For
this you can use an event procedure in the control's KeyPress event,
like this:
'----- start of example code -----
Private Sub LastName_KeyPress(KeyAscii As Integer)
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End Sub
'----- end of example code -----
Many people like this approach.
Given these various approaches to forcing upper case, I still have to
ask, why? Why not let people enter names in mixed case? They're
prettier and easier to read that way. If you're afraid they won't use
mixed case, you can check in the control's AfterUpdate event to see if
they used all lower or all upper case, and correct the case to "proper
case" using the StrConv function if they did. Of course, for some names
that won't give the correct capitalization, but you can leave it to the
user to correct that. You can even make some effort to trap many such
cases in code.