Title Case

jonp

Registered User.
Local time
Today, 15:56
Joined
Sep 27, 2000
Messages
42
Hello yall!

Does anyone know the code to make a text field change to title case no matter what the user enters. I know how to make all caps and all lower case, but not title case.

Any suggestions would be greatly appreciated.

Thanks from Texas,
JONP
 
MyField=StrConv(MyField,vbProperCase)

HTH
 
You could use a function like the one below. You'll need to experiment with where to call it, though - in my tests, it won't work in the BeforeUpdate event for a text box, and if placed in the AfterUpdate event, it returns the focus to that text box after the user updates and leaves it (which may be inconvenient in some applications). Note that the Option Compare Binary statement is required at the top of the module - otherwise, upper case letters may not be distinguished from lower case.

Text0 = TitleCase(Text0)

...

Option Compare Binary
Option Explicit
Public Function TitleCase(V As Variant) As String
Dim Hold As String, LastChr As String, ThisChr As String, I As Integer
If IsNull(V) Then TitleCase = "": Exit Function
Hold = ""
LastChr = " "
For I = 1 To Len(V)
ThisChr = Mid(V, I, 1)
If UCase$(LastChr) = LCase$(LastChr) Then 'last character was not a letter
Hold = Hold & UCase$(ThisChr)
Else 'last character was a letter
Hold = Hold & LCase$(ThisChr)
End If
LastChr = ThisChr
Next I
TitleCase = Hold
End Function


[This message has been edited by AlanS (edited 04-25-2001).]
 
Thanks KevinM and AlanS. The suggestions worked brilliantly.

Have a fabulous week!

JONP from Texas
 

Users who are viewing this thread

Back
Top Bottom