The following function converts a string to proper case. In addition to
capitalizing the first letter and after a space it also capitalizes after an
open parentheses, a forward slash, and an open bracket character.
To use it, first cut and paste the function to a global module (Modules from
the database window). Then create an update query to set each field to the
result of calling the function on the field's current value. The example
below sets a CompanyName field in a table named Customer2:
UPDATE Customer2 SET Customer2.CompanyName = ProperCase([CompanyName]);
Please note there is no error-handling. If an error occurs, I'd suggest
returning the original string.
Hope that helps.
Sprinks
Public Function ProperCase(strParam As String) As String
Dim strWS As String ' Working string
Dim inti, intL, intChr As Integer
Dim blnCapNext As Boolean
' Convert string to lower case & determine length
strWS = LCase(strParam)
intL = Len(strWS)
' Set blnCapNext to True to capitalize first letter
blnCapNext = True
' Loop through each character in the string.
' If it is a space, open parentheses, forward slash, or open bracket,
' set blnCapNext to True to capitalize the next letter
For inti = 1 To intL
intChr = Asc(Mid(strWS, inti, 1))
Select Case intChr
'Space, open paren, forward slash, open bracket
Case 32, 40, 47, 91
blnCapNext = True
' Lower case letter
Case 97 To 122
If blnCapNext Then
strWS = Left(strWS, inti - 1) & _
Chr(intChr - 32) & Right(strWS, intL - inti)
End If
blnCapNext = False
Case Else
blnCapNext = False
End Select
Next inti
' Set function value to the value of the working string
ProperCase = strWS
End Function
Novice2000 said:
Hi,
I have inherited an access table in which all of the entries (270,000 of
them) have been made in all caps. I need to convert the table to "proper" so
that the first letter is capitalized and the remainder is lower case.
Can I just update the field somehow?? Thanks