So your problem is using a non-unique value for your search. I made a few changes. Your listbox did not specify the width for the last column, so I set it to 80, and added another 0 width column.
ColumnWidth property for lstLookup now reads: 100 pt;60 pt;40 pt;80 pt;70 pt;80 pt;0 pt
Then I added one line to your search button code:
If rngFind.Row > 1 Then
lstLookup.AddItem rngFind.Value
lstLookup.List(lstLookup.ListCount - 1, 1) = rngFind.Offset(0, 1)
lstLookup.List(lstLookup.ListCount - 1, 2) = rngFind.Offset(0, 8)
lstLookup.List(lstLookup.ListCount - 1, 3) = rngFind.Offset(0, 2)
lstLookup.List(lstLookup.ListCount - 1, 4) = rngFind.Offset(0, 4)
lstLookup.List(lstLookup.ListCount - 1, 5) = rngFind.Offset(0, 7)
lstLookup.List(lstLookup.ListCount - 1, 6) = rngFind.Row
End If
This means that now you have the row number of the search results available to do your textbox updating. Which requires a change to the double-click event for your listbox (changed it as little as possible):
Private Sub lstLookup_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
'declare the variables
Dim cPayroll As Integer
Dim i As Integer
Dim findvalue
'error block
On Error GoTo errHandler:
'get the select value from the listbox
For i = 0 To lstLookup.ListCount - 1
If lstLookup.Selected(i) = True Then
cPayroll = lstLookup.List(i, 6)
End If
Next i
'find the payroll number
Set findvalue = Sheet11.Range("A" & cPayroll)
'add the database values to the userform
cNum = 19
For x = 1 To cNum
Me.Controls("Reg" & x).Value = findvalue
Set findvalue = findvalue.Offset(0, 1)
Next
'disable adding
Me.cmdAdd.Enabled = False
Me.cmdEdit.Enabled = True
' deal with textbox formatting issue
Reg6.Value = Format(Reg6.Value, "h:mm AM/PM")
'error block
On Error GoTo 0
Exit Sub
errHandler::
MsgBox "An Error has Occurred " & vbCrLf & "The error number is: " _
& Err.Number & vbCrLf & Err.Description & vbCrLf & _
"Please notify the administrator"
End Sub
Bookmarks