Pookiemeister
Well-known Member
- Joined
- Jan 6, 2012
- Messages
- 626
- Office Version
- 365
- 2010
- Platform
- Windows
I might be overthinking this but I have 3 textboxes on a userform. So the way we setup our email address is
firstname.lastname@company.com
textbox1 = first name
textbox2 = last name
textbox3 = email address
I'm trying to reverse our company's email address format. So if the user enters the email address, the code will extract the first and last name and put them in their appropriate textboxes. I was able to fill the first name textbox but not the last name textbox.
Also, when I hover over this part of the code I find where the error 13 type mismatch occurs.
Why does it occur?
How can I fix it so it does what I want it to do.
Thank you.
firstname.lastname@company.com
textbox1 = first name
textbox2 = last name
textbox3 = email address
I'm trying to reverse our company's email address format. So if the user enters the email address, the code will extract the first and last name and put them in their appropriate textboxes. I was able to fill the first name textbox but not the last name textbox.
VBA Code:
Private Sub TextBox1_Change()
If (Me.TextBox1.Text) = "" Then Me.TextBox3 = Me.TextBox1.Text & "."
End Sub
Private Sub TextBox2_Change()
If (Me.TextBox2.Text) = "" Then Me.TextBox3 = Me.TextBox1.Text & "." & Me.TextBox2.Text & "@sanofi.com"
End Sub
Private Sub TextBox3_Change()
Dim str As String
str = Me.TextBox3.Text
If InStr(Me.TextBox3.Text, ".") > 0 Then Me.TextBox1.Text = Left(Me.TextBox3.Text, InStr(Me.TextBox3.Text, ".") - 1)
If InStr(str, "@") > 0 Then Me.TextBox2.Text = Right(str, InStr(str, "@"))
End Sub
Private Sub UserForm_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Me.TextBox1.Enabled = False
Me.TextBox2.Enabled = False
Me.TextBox3.Enabled = True
End Sub
Private Sub UserForm_Initialize()
Me.TextBox1.Enabled = True
Me.TextBox2.Enabled = True
Me.TextBox3.Enabled = False
End Sub
Also, when I hover over this part of the code I find where the error 13 type mismatch occurs.
VBA Code:
Me.TextBox2.Text = Right(str, InStr(str, "@")) - 1 [B]'InStr(str, "@")=13[/B]
Why does it occur?
How can I fix it so it does what I want it to do.
Thank you.