Format Name String

Hello,
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.

Title
First
Middle
Last
Suffix
Gunit2507Asked:
Who is Participating?
 
List244Commented:
Assuming your string is in the form:

"Title First Middle Last Suffix"
"Title First Middle Last"
"Title First Middle"
"Title First"
"Title"
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"
0
 
List244Commented:
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.
0
 
patingsadagatCommented:
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.
0
 
List244Commented:
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.
0
 
patingsadagatCommented:
given that way, it would definitely work list244.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.