Results 1 to 6 of 6

Thread: Proper Case

  1. #1
    Devinder
    Guest

    Proper Case

    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?

  2. #2
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Proper Case

    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 <img src=/S/wink.gif border=0 alt=wink width=15 height=15>)

  3. #3
    3 Star Lounger
    Join Date
    Mar 2001
    Location
    Minneapolis, Minnesota, USA
    Posts
    262
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Proper Case

    Post it, and they will come.
    <font face="Comic Sans MS"><font color=blue>~Shane</font color=blue></font face=comic>

  4. #4
    4 Star Lounger
    Join Date
    Dec 2000
    Location
    London, Ontario, Canada
    Posts
    437
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Proper Case

    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 <A target="_blank" HREF=http://www.helenfeddema.com/access.htm>this site</A> and download Archon Column # 82 at the bottom.

  5. #5
    Devinder
    Guest

    Re: Proper Case

    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

  6. #6
    2 Star Lounger
    Join Date
    Dec 2000
    Posts
    188
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Proper Case

    Cool, you can also find similar code at <A target="_blank" HREF=http://www.mvps.org/access/>http://www.mvps.org/access/</A>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •