BarefootPaul
Board Regular
- Joined
- Jul 21, 2011
- Messages
- 54
I have a listbox that pulls in some records based on a last name selected in a combobox. It works like a charm and here is the code.
The problem is selecting the record and then populating the corresponding data into textboxes on the userform. I would like to set the g_rFound variable when I select the record (rather than doing it when populating the listbox, as I am currently). I haven't figured out how to do this from the reading on the forum and some other resources I have.
I am populating the textboxes like this (below), currently, and it works if there is only 1 matching last name in the dataset. Otherwise it always pulls the last record (since that is when I set the g_rFound variable).
Any help/direction is highly appreciated. I'm using Excel 2010 on Windows 7.
Code:
With wsClients
Set rSource = .Range("D5", Range("D" & lLastRow).End(xlDown))
lstClients.Clear
sLName = cboLName.Value
For Each rCell In rSource
If rCell.Value = sLName Then
sFound = rCell.Address
Set rFound = Range(sFound)
Set g_rFound = rFound 'global variable used elsewhere in the userform code
sBillingID = rFound.Offset(0, -3).Value
sMaineCare = rFound.Offset(0, -2).Value
sFName = rFound.Offset(0, -1).Value
dDOB = rFound.Offset(0, 1).Value
With lstClients
.AddItem
.Column(0, lstClients.ListCount - 1) = rFound
.Column(1, lstClients.ListCount - 1) = sBillingID
.Column(2, lstClients.ListCount - 1) = sMaineCare
.Column(3, lstClients.ListCount - 1) = sFName
.Column(4, lstClients.ListCount - 1) = sLName
.Column(5, lstClients.ListCount - 1) = dDOB
End With
End If
Next rCell
If lstClients.ListCount > 0 Then
lstClients.Height = lstClients.ListCount * 18
lstClients.Visible = True
Else
lblNoMatches.Visible = True
End If
End With
The problem is selecting the record and then populating the corresponding data into textboxes on the userform. I would like to set the g_rFound variable when I select the record (rather than doing it when populating the listbox, as I am currently). I haven't figured out how to do this from the reading on the forum and some other resources I have.
I am populating the textboxes like this (below), currently, and it works if there is only 1 matching last name in the dataset. Otherwise it always pulls the last record (since that is when I set the g_rFound variable).
Code:
txtFName.Value = g_rFound.Offset(0, -1).Value
txtLName.Value = g_rFound.Value
txtBillingID.Value = g_rFound.Offset(0, -3).Value
txtMaineCare.Value = g_rFound.Offset(0, -2).Value
txtDOB.Value = g_rFound.Offset(0, 1).Value
Any help/direction is highly appreciated. I'm using Excel 2010 on Windows 7.