Field with Proper Case

G

Guest

How do I make any text entered in a table always save it as proper case? for
instance if I have a text field say Lastname, and in it I put the last name
of the person, no matter what the caps lock is, if i type smith it will
always make it Smith? If I type SMITH it will convert it to Smith?

I have tried the Format >L<??????? and it doesn't work,
I have tried to put in an input mask but if I type smith it balks and says
wrong format.

Is there a function i can use like excell =PROPER(A2)
 
A

Allen Browne

You can't do it with the Format or Input Mask properties.

You can use the AfterUpdate event procedure of the text box on your form.
Use StrConv() to convert to proper case.

You're likely to upset lots of people though: van Leen, MacBeth, d'Vinci,
and so on.
 
J

John W. Vinson

How do I make any text entered in a table always save it as proper case? for
instance if I have a text field say Lastname, and in it I put the last name
of the person, no matter what the caps lock is, if i type smith it will
always make it Smith? If I type SMITH it will convert it to Smith?

You can't do it in a Table - tables have no usable events - but you can do it
in a Form. Here's a little routine which I use in the AfterUpdate of each
textbox which should be in proper case:

Public Function SetProper(ctl As Control)
' Comments :
' Parameters: ctl -
' Returns : -
' Modified : 01/29/02 by JWV
'
' --------------------------------------------------
' Sets the value in the control to Proper Case if it is currently all
lower case
On Error GoTo PROC_ERR


If StrComp(ctl.Value, LCase(ctl.Value), vbBinaryCompare) = 0 Then
ctl.Value = StrConv(ctl.Value, vbProperCase)
End If

Proc_Exit:
Exit Function

PROC_ERR:
MsgBox "Error " & Err.Number & " in SetProper:" _
& vbCrLf & Err.Description
Resume Proc_Exit


End Function


Just put

=SetProper(Form.[txtFirstName])

in the AfterUpdate event line of the txtFirstName control. It will take any
entry in all lower case and change it to Proper Case (Each Word Capitalized);
an entry in mixed case or all upper case will be left alone.

John W. Vinson [MVP]
 

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