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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sentence Case

Status
Not open for further replies.

Fibee

Programmer
Jul 26, 2002
39
GB
Hi, does anyone know a way within Access97 that you can format a text field into Sentence case (ie, first letter capital the rest lower cae?). I can only find the Ucase and Lcase functions. Is there a VBA module available that will do this?
 
Use the strConv function. Here's an example from the debug window.

strSent = "tHe QuIcK bRoWn Fox."
mySent = strConv(left(strSent, instr(strSent," ")-1),3) & strConv(mid(strSent, instr(strSent, " ")),2)
? mySent
The quick brown fox.

You could easily create a User Defined Function to handle this situation, e.g.
Code:
Function SentCase(pstr As String) As String
Dim strSent As String, mySent As String

strSent = pstr
mySent = StrConv(Left(strSent, InStr(strSent, " ") - 1), 3) & StrConv(Mid(strSent, InStr(strSent, " ")), 2)
SentCase = mySent

End Function-
…then test it from the debug window with:

? sentcase("tHe QUICK bRoWn fox JUMPED oveR The LAzy Dog.")
The quick brown fox jumped over the lazy dog.
 
Cheers for that. It works a treat. I have had to make a couple of amendments as some of my text strings contain only one word and therefore no spaces.
Fi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top