• Proper Case

    Author
    Topic
    #1769387

    Would anybody be interested in a Function that changes upper case to proper case and takes care of names like McDonald, O’Meara, John Paul III, etc?

    Viewing 2 reply threads
    Author
    Replies
    • #1783183

      You might want to post this in the VB/VBA forum. There are a few folks there who are quite interested in functions of the sort. (Not to mention any names….cough…cough…Chris Greaves…cough…cough wink)

    • #1783184

      Post it, and they will come.

      • #1783219

        Public Function Proper(anyValue As Variant) As Variant
        ‘ Accepts: a text value
        ‘ Purpose: converts first letter of each word to uppercase
        ‘ Returns: converted text value

        Dim i As Integer
        Dim theString As String
        Dim currChar As String
        Dim prevChar As String
        Dim prevChar2 As String
        Dim prevChar3 As String

        If IsNull(anyValue) Then
        Exit Function
        End If

        currChar = ” ”
        prevChar = ” ”
        prevChar2 = ” ”
        prevChar3 = ” ”

        theString = CStr(anyValue)
        For i = 1 To Len(theString) ‘Go through string char by char.
        currChar = Mid(theString, i, 1) ‘Get the current character.

        Select Case prevChar ‘If previous char is letter,
        ‘this char should be lowercase.
        Case “I”
        If currChar = “I” And (prevChar2 = ” ” Or prevChar2 = “I”) Then
        Mid(theString, i, 1) = UCase(currChar)
        Else
        Mid(theString, i, 1) = LCase(currChar)
        End If
        Case “c”
        If i = 3 And prevChar2 = “M” Then
        Mid(theString, i, 1) = UCase(currChar)
        Else
        Mid(theString, i, 1) = LCase(currChar)
        End If
        Case “‘”
        If currChar = “s” Then
        mid(theString, i, 1) = LCase(currChar)
        End If
        Case “A” To “Z”, “a” To “z”
        Mid(theString, i, 1) = LCase(currChar)

        Case Else
        Mid(theString, i, 1) = UCase(currChar)

        End Select
        prevChar3 = prevChar2
        prevChar2 = prevChar
        prevChar = currChar

        Next i
        Proper = CVar(theString)

        End Function

    • #1783186

      Helen Fedemma wrote a very good column in todays Woody’s Access Watch about this subject. You can download an excerpt from her web page go to this site and download Archon Column # 82 at the bottom.

    Viewing 2 reply threads
    Reply To: Proper Case

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: