Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Captilization question?

Status
Not open for further replies.

WB786

MIS
Joined
Mar 14, 2002
Messages
610
I have a code to make the first letter capital which works great. Now one of the user said if they have a last name with two last names and a hyphen how do you make the second last name after the hyphen to be a capital as well.

Anyone got any idea on this.

Thanks,
WB
 
Hi,

Here's a function that might help. It assumes htere are no spaces between the hyphon i.e. "parker-bowles" as opposed to "parker - bowles"

Code:
Function GetName(strName As String)
    Dim strReturnName As String
    Dim intFP As Integer 'First Pass
    If IsNull(strName) Or strName = "" Then Exit Function
    
    intFP = True
    Do Until strName = ""
        If Left(strName, 1) = "-" Then
            strReturnName = strReturnName & UCase(Left(strName, 2))
            strName = Right(strName, Len(strName) - 1)
        Else
            If intFP Then
                strReturnName = strReturnName & UCase(Left(strName, 1))
            Else
                strReturnName = strReturnName & Left(strName, 1)
            End If
        End If
        strName = Right(strName, Len(strName) - 1)
        intFP = False
    Loop
    GetName = strReturnName
End Function

birklea birklea ~©¿©~ <><
I know what I know...don't presume that I know what I don't! Smithism!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top