Had already looked in there and the only thing I could find which nearly did waht i require is vbPropercase.
Only problem with this is that it converts the 1st letter of each word in the string to UpperCase i.e. The Dog Is Black. The Cat Is Brown. as opposed to converting just the 1st letter of the sentence, and after full stop e.g The dog is black. The cat is brown.
Here's some code I wrote to tidy up names from an input file. You're welcome to use it though you may need to modify if you are using a full memo field - I can't remember if string is limited to 256 bytes?
[green]Public Function Title_Case(Name As String) As String
' Change Name to Title Case. Include Mac, Mc, O', de
Dim L As Integer
Dim C As String
Dim I As Integer
Dim Word() As String
Dim TempStr As String
' Start by trimming spaces, removing multiple spaces and setting all to lower case
Name = LCase(Trim(Name))
Do
If InStr(Name, " ") = 0 Then Exit Do
Name = Replace(Name, " ", " ")
Loop
' Split Name into an array (one word per element) after replace ,' and - with space
' Need to keep Name in order to put spaces or commas full stops back at the end
TempStr = Name
Word = Split(TempStr, " ")
For I = 0 To UBound(Word)
Word(I) = UCase(Left(Word(I), 1)) & Mid(Word(I), 2, Len(Word(I)))
Word(I) = PreNames(Word(I))
Next I
Title_Case = ""
For I = 0 To UBound(Word) - 1
Title_Case = Title_Case & Word(I) & " "
Next I
Title_Case = Title_Case & Word(UBound(Word))
For L = 1 To Len(Name)
If Asc(Mid(Name, L, 1)) < 65 Then
Title_Case = Left(Title_Case, L - 1) & Mid(Name, L, 1) & Mid(Title_Case, L + 1, Len(Title_Case) - L)
End If
Next L
End Function
Public Function PreNames(Text As String) As String
PreNames = Text
If Left(Text, 3) = "Mac" Then
PreNames = Left(Text, 3) & UCase(Mid(Text, 4, 1)) & Mid(Text, 5, Len(Text) - 4)
End If
If Left(Text, 2) = "Mc" Then
PreNames = Left(Text, 2) & UCase(Mid(Text, 3, 1)) & Mid(Text, 4, Len(Text) - 3)
End If
If Left(Text, 2) = "O'" Then
PreNames = Left(Text, 2) & UCase(Mid(Text, 3, 1)) & Mid(Text, 4, Len(Text) - 3)
End If
End Function [/green]
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.