Dan Swartz
Board Regular
- Joined
- Apr 17, 2020
- Messages
- 53
- Office Version
- 365
- Platform
- Windows
I have a userform for pulling a customer's information. it works great. But if I have two or more customers with the same name. It only finds the first name. I live in a community of Amish. It's not uncommon to have 5 - 10 customers with the same name.
I don't even know where to start.
Is there a way to search for a name, display all customers with the same name, but show their address so i would know which customer is the correct one and then be able to choose that customer?
This is my code for the current Customer Form.
I don't even know where to start.
Is there a way to search for a name, display all customers with the same name, but show their address so i would know which customer is the correct one and then be able to choose that customer?
This is my code for the current Customer Form.
VBA Code:
Private Sub FindCust_Click()
Dim f As Range
If CustomerName.Value = "" Then
MsgBox "Please enter a customer name"
CustomerName.SetFocus
Exit Sub
End If
Set f = Sheet2.Range("A:A").Find(CustomerName.Value, , xlValues, xlWhole, , , False)
If Not f Is Nothing Then
Address1.Text = Sheet2.Cells(f.Row, 2).Value
Address2.Text = Sheet2.Cells(f.Row, 3).Value
City.Text = Sheet2.Cells(f.Row, 4).Value
State.Text = Sheet2.Cells(f.Row, 5).Value
Zip.Text = Sheet2.Cells(f.Row, 6).Value
Email.Text = Sheet2.Cells(f.Row, 7).Value
Else
MsgBox ("Customer does not exist"), vbOKOnly
CustomerName.SetFocus
End If
End Sub