FIRST LETTER CAPITAL

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

Guest

LCase, UCase, ProperCase. Is there a simple way to just cap the first letter of each word and leave the rest alone

Thanks in advance
 
StrConv("String", vbProperCase)

--

Ken Snell
<MS ACCESS MVP>

Sue said:
LCase, UCase, ProperCase. Is there a simple way to just cap the first
letter of each word and leave the rest alone?
 
That won't work. It will make any subsequent upper case letters lower case. I'm just looking to make the first letter upper case.
 
Sue,

Public Function FirstCharUC(sText As String) As String
Dim sTmp() As String
Dim iCtr As Integer

If Len(Trim(sText)) > 0 Then
sTmp = Split(sText)

For iCtr = 1 To UBound(sTmp)
sTmp(iCtr) = UCase(Left(sTmp(iCtr), 1)) & Mid(sTmp(iCtr), 2)
Next iCtr

FirstCharUC = Join(sTmp)
Else
FirstCharUC = sText
End If
End Function

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia

Microsoft Access 2003 VBA Programmer's Reference
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0764559036.html


Sue said:
That won't work. It will make any subsequent upper case letters lower
case. I'm just looking to make the first letter upper case.
 
Hallo,

Or this ;-)

Place it in a query field:
UCase(Left([YourField];1))+LCase(Right([YourField];Len([YourField])-1))


Regards,
Harmannus
 
Sue,

If you want to change the text after it has been entered into a textbox by
the user, then add the following code to your textbox's AfterUpdate event:
Private Sub txtMyTextBox_AfterUpdate()
Me!txtMyTextBox = FirstCharUC(Me!txtMyTextBox)
End Sub

Make sure to rename txtMyTextBox to whatever name you've given to your
textbox.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia

Microsoft Access 2003 VBA Programmer's Reference
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0764559036.html
 
Change the 1 ot a 0 in this line:

For iCtr = 1 To UBound(sTmp)

The split function retruns a 0 based array so the way it was it was starting
with the second word instead of the first.

Sue Harsevoort

Sue said:
Works great. Want I was looking for.

Have one problem though. If the very first letter in the field is lower
case it doesn't capitalize that field. Is there something I can change to
ensure it also looks at the very first character in the field?
 
Back
Top