Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Format text -- first letter capitalized

Status
Not open for further replies.

KerryL

Technical User
May 7, 2001
545
US
I know I can use the ">" character in the format property of a text cell to display the contents in all CAPS.

However, is there a setting I can use to automatically capitalize only the first letter of the contents of a text box?

IOW, if the contents of the text box = wyoming
then using ">" would force the report to display the contents as 'WYOMING'.

Is there a format setting I can use to automatically display the contents as 'Wyoming'?

I was unable to find anything in the Access help files.

Thanks in advance.
 
There is a vba function called
strconv([nameoffield],1)
1=uppercase
2=lowercase
3=propercase

Hope it helps

Jason
 
This capitalizes only the first letter--if you put a capital later in the sentence, it will not change it to lowercase.

In a module, place the following code:

Function CapitalizeFirst(Str)

Dim strTemp As String
strTemp = Trim(Str)
CapitalizeFirst = UCase(Left(strTemp, 1)) & Mid(strTemp, 2)

End Function

In the AfterUpdate event procedure of a field, insert the following code:

Private Sub txtFieldName_AfterUpdate()

If Not (IsNull(Me!txtFieldName)) Then
Me!strFieldName = CapitalizeFirst((Me!txtFieldName))

End If

End Sub
Linda Adams
Linda Adams/Emory Hackman Official Web site Official web site for actor David Hedison:
 
The code Garridon gave indeed would make Wyoming out of wyoming but would convert new york to New york, for instance. The code I'd use would be

Function CapitalizeFirst(Str)

dim x as byte
dim sw as boolean

sw=false
for x=1 to len(str)
if sw=true then mid(str,x,1) = ucase(mid(str,x,1))
sw=false
if mid(str,x,1)= "" then sw = true
next x

CapitalizeFirst = Str
End Function

Just a thought...

Niki.
 
Eep.. Error..


if mid(str,x,1)= " " then sw = true

Niki
 
I'm sure this is considered spamming, but I one more made a mistake. I'm so sorry...

Here's the code that should work:

Function CapitalizeFirst(Str)

dim x as byte
dim sw as boolean

sw=true
for x=1 to len(str)
if sw=true then mid(str,x,1) = ucase(mid(str,x,1))
sw=false
if mid(str,x,1)= " " then sw = true
next x

CapitalizeFirst = Str
End Function

 
Thank you all. I will give this a try.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top