1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| Sub Lookup()
'declare the variables
Dim Due As Variant
'error statement
On Error GoTo errHandler:
'clear the listbox
lstLookup.RowSource = ""
'set the variable
Due = Me.cboStart.Value
'if "Nouveau" or "Unique" is selected run a different filter
If Me.cboStart.Value = "Unique" Or Me.cboStart.Value = "Nouveau" Then
Sheet2.Range("N7").Value = Me.cboStart.Value
AdvFilter_Once
'if the results are nil then clear the rowsource to avoid an error
If Sheet2.Range("T7").Value = "" Then
lstLookup.RowSource = ""
Else
'add range to rowsource if range has values
lstLookup.RowSource = "Filter_Staff"
End If
Exit Sub
End If
'if no date selected for criteria
With Sheet2
If Me.cboStart = "" Then
.Range("O7").Value = ""
.Range("P7").Value = ""
.Range("Q7").Value = Me.txtLookup
.Range("R7").Value = Me.cboDepartment
.Range("S7").Value = Me.txtLookup2
'if date is selected
Else
.Range("P7").Value = "=""<""&TODAY()" & "+" & Due
.Range("O7").Value = "=" & ">""&TODAY()"
.Range("Q7").Value = Me.txtLookup
.Range("R7").Value = Me.cboDepartment
.Range("S7").Value = Me.txtLookup2
End If
End With
'run the filter
AdvFilter
'if the results are nil then clear the rowsource to avoid an error
If Sheet2.Range("T7").Value = "" Then
lstLookup.RowSource = ""
Else
'add range to rowsource if range has values
lstLookup.RowSource = "Filter_Staff"
End If
'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 |
Partager