I have a form with a combo box, and I would like the corresponding values related to the selected ID from the combo box to display in text boxes. The issue is that the text boxes only display the values from the last added ID. Here is my code, and thank you in advance for your help.
lastrow = wscontact.Cells(wscontact.Rows.Count, 1).End(xlUp).Row
For i = 2 To lastrow + 1
If Val(Me.txtindexcontact) = Val(wscontact.Cells(i, 12).Value) Then
If Trim(UCase(cbContact.Value)) = Trim(UCase(wscontact.Cells(i, 3).Value)) & " " & Trim(UCase(wscontact.Cells(i, 4).Value)) Then
MsgBox "find"
FrmVisites.txtfirstname = wscontact.Cells(i, 3).Value
FrmVisites.txtlastname = wscontact.Cells(i, 4).Value
FrmVisites.txtposition = wscontact.Cells(i, 5).Value
FrmVisites.txtphone1 = wscontact.Cells(i, 6).Value
FrmVisites.txtextension = wscontact.Cells(i, 7).Value
FrmVisites.txtemail = wscontact.Cells(i, 8).Value
FrmVisites.txtcellnumber = wscontact.Cells(i, 9).Value
Exit Sub
End If
End If
Next i
waiil is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2
If Me.txtindexcontact = wscontact.Cells(lastrow + 1, 12).Value then you would only get the last values from the wscontact combo box.