Hi Mike
Thanks for your reply. I have played around with amending the code and have got it to take account of O'Brien, McDonald/MacDonald etc. However there is a problem when it comes to names like Machin which it converts to MaChin!! Any ideas on how one could get round that? I have only thought about, but not done, a possible "exceptions to the rule" table that is called upon (at the moment I have the exceptions hard-coded in, see below):
Function ProperLast(strTxt As String) As String
' Comments :
' Parameters : strTxt -
' Returns : String -
' Created :
' Modified :
'
' --------------------------------------------------------
'---------------------------
' modul General
'
' Makes all characters lower case and then
' make every character before a space upper case
' Special check for McArthur and O'Neil
' EX: txtVar = ProperLast("" & Me!Name & "")
'
' Changed 12-07-98
'---------------------------
Dim strCHAR As String * 1
Dim strTxtTmp As String
Dim strWord As String
Dim intIX As Integer
On Error GoTo errProperLast
strCHAR = ""
strTxtTmp = ""
' Make all lowercase
strTxt = LCase(strTxt) & " "
' Search for spaces chr(32) or " - " chr(45) or " / " chr(47)
For intIX = 1 To Len(strTxt)
strCHAR = Mid(strTxt, intIX, 1)
strWord = strWord & strCHAR
' If a space or "-" is found make first character uppercase
If strCHAR = Chr(32) Or strCHAR = Chr(45) Or strCHAR = Chr(47) Then
strWord = UCase(Left(strWord, 1)) & Mid(strWord, 2, Len(strWord))
' Check for McDonald, or O'Brien
If Left(strWord, 2) = "Mc" Or Left(strWord, 2) = "O'" Then
strWord = Left(strWord, 2) & UCase(Mid(strWord, 3, 1)) & Mid(strWord, 4, Len(strWord))
'Check for MacDonald
ElseIf Left(strWord, 3) = "Mac" Then
strWord = Left(strWord, 3) & UCase(Mid(strWord, 4, 1)) & Mid(strWord, 5, Len(strWord))
'Check for Mace, Macey, Machin etc.
If strWord = "Mace " Or strWord = "Macey " Or strWord = "Machen " Or strWord = "Machin " Or strWord = "Machell " Or strWord = "Mack " Then
strWord = Left(strWord, 3) & LCase(Mid(strWord, 4, 1)) & Mid(strWord, 5, Len(strWord))
End If
End If
strTxtTmp = strTxtTmp & strWord
strWord = ""
End If
Next
ProperLast = Trim(strTxtTmp)
exitProperLast:
Exit Function
errProperLast:
MsgBox Error$ & Chr(13) & "Nr: " & Err, 48, "ProperLast"
Resume exitProperLast
End Function
------------------------------------------
Have you Mike, or anyone else , got any further modifications that you could suggest to take account of these "unusual" names (my name is unusual enough for me to feel OK about calling other names unusual!!). I would also like to take account of non-English based names - van Houten, de Faria, etc.
Rich Gorvin
[This message has been edited by Rich@ITTC (edited 03-15-2001).]