Format Name String

Posted on 2006-06-08
Last Modified: 2010-04-30
I am trying to create a form that is very similar to outlook's name dialog. When this form loads it takes the value from the variable MyString and I want it seperate the diffrent elements of a name into the following textboxes below. Although, not every person is going to have all the elements of a name.

Question by:Gunit2507
    LVL 8

    Accepted Solution

    Assuming your string is in the form:

    "Title First Middle Last Suffix"
    "Title First Middle Last"
    "Title First Middle"
    "Title First"
    Depending on how many they have:

    Dim Splitter() As String
    Splitter = Split(Data, " ")
    For i = 0 To UBound(Splitter)
        Select Case (i)
            Case 0: Title.Text = Splitter(i)
            Case 1: First.Text = Splitter(i)
            Case 2: Last.Text = Splitter(i)
            Case 3: Middle.Text = Splitter(i)
            Case 4: Suffix.Text = Splitter(i)
        End Select
    Next i

    Where Data would be their name in the format: "Title First Middle Last Suffix"
    LVL 8

    Expert Comment

    That will allow you to split it into the boxes no matter how many of the allowed names they have.
    From nothing to all of them without problem.
    LVL 5

    Expert Comment

    what if there's no title list244? it all depends on where the variable MyString came from Gunit2507. Was it an input or from a database.
    LVL 8

    Expert Comment

    Patingsadaqat, I do not know how his data comes in, which is why I said assuming it comes in in that way, my method would work.
    If there were no title in the method I provided, then it would fill no text boxes.
    LVL 5

    Expert Comment

    given that way, it would definitely work list244.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
    Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now