FIRST LETTER CAPITAL

S

Sue

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
 
K

Ken Snell

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?
 
S

Sue

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.
 
G

Graham R Seach

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.
 
H

Harmannus

Hallo,

Or this ;-)

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


Regards,
Harmannus
 
G

Graham R Seach

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
 
S

Sue Harsevoort

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?
 

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