I am looking to loop through all of the rows in a listbox. For each row in the listbox, I want to check if the last name in the Labor column is contained in any records in the Labor column of a recordset. If it is contained, add the column value to a variable to eventually be shown in another listbox. It seems that the loop is not working correctly and the EstHours is always 0 and the instr function doesn't seem to be working.
Does anyone have any thoughts on what I am doing wrong??
Does anyone have any thoughts on what I am doing wrong??
Code:
Sub ScheduledHours()
'on error goto errorhandler
Dim LastName As String
Dim FullName As Variant
Dim EstHours As Long
Me.lstscheduled.RowSource = ""
With lstlabor
For i = 0 To .ListCount - 1
LastName = fExtractLastNAme(lstlabor.Column(4, i))
EstHours = 0
Dim rs As Recordset
Set rs = Me.subwo.Form.RecordsetClone
Do Until rs.EOF
FullName = rs!Labor
If InStr(1, FullName, LastName) = 1 Then
EstHours = EstHours + rs!EstimatedTime
End If
rs.MoveNext
Loop
Set rs = Nothing
Me.lstscheduled.AddItem LastName & ";" & lstlabor.Column(6, i) & ";" & EstHours
Next i
End With
ProcedureExit:
Exit Sub
ErrorHandler:
MsgBox "Error" & ": " & Err.Number & vbCrLf & "Description: " _
& Err.Description, vbExclamation, Me.Name & ".ScheduledHours"
Resume ProcedureExit
End Sub