Capitalizing Names Automatically

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to set a text box so that it will automatically capitalize a name but I can't find it anywhere. DOes anyone know the formula I would use to do that
Thanks
 
I need to set a text box so that it will automatically capitalize a name but I can't find it anywhere. DOes anyone know the formula I would use to do that?
Thanks

Code the AfterUpdate event of that control:
[ControlName] = StrConv([ControlName],3)

This will change "frank smith" to "Frank Smith".
Unfortunately it will also improperly change "mcdonald" to "Mcdonald"
and "van Beethoven" to "Van Beethoven".
 
Use the StrConv function, example:

StrConv("aBcdEFg", vbProperCase)

which returns the following:

Abcdefg

If you have more then one word in your string, every word
will be capitalized.

Put this in the BeforeUpdate event procedure of the text
box:

Me.Text1 = StrConv(Me.Text1, vbProperCase)

Replace Text1 in both places with the real name of your
text box.

Karibusz
-----Original Message-----
I need to set a text box so that it will automatically
capitalize a name but I can't find it anywhere. DOes
anyone know the formula I would use to do that?
 
Sorry! Use the AfterUpdate event instead of the
BeforeUpdate event. I thought in one way and wrote in
another way... :)

Karibusz
 
Place this function in a standard module: (Watch for line
wrapping)

Function ProperCase(strText As String)
Dim i As Integer, iSlen As Integer
Dim strCapAfter

strText = StrConv(strText, 3)

i = InStr(2, strText, "-")
If i <> 0 And i <> Len(strText) Then
Mid$(strText, i + 1, 1) = UCase$(Mid$(strText, i +
1, 1))
End If

strCapAfter = Array("mc", "m'", "o'")
For i = 0 To UBound(strCapAfter)
iSlen = Len(strCapAfter(i))

If StrComp(Left$(strText, iSlen), strCapAfter(i),
vbTextCompare) = 0 And iSlen < Len(strText) Then
Mid$(strText, iSlen + 1, 1) =
UCase$(Mid$(strText, iSlen + 1, 1))
i = UBound(strCapAfter)
End If
Next

ProperCase = strText
End Function

Call the function like this:
Controlname.Value = ProperCase(Controlname.Value)
This should deal with most of the problems including
macdonald etc

Dave
-----Original Message-----
I need to set a text box so that it will automatically
capitalize a name but I can't find it anywhere. DOes
anyone know the formula I would use to do that?
 
Dave Jones said:
Place this function in a standard module: (Watch for line
wrapping)
Call the function like this:
Controlname.Value = ProperCase(Controlname.Value)
This should deal with most of the problems including
macdonald etc

Except that some people use Macdonald, and some use MacDonald...
 
Back
Top