C
Chris K
I'm using one combo (cboFilters) so the user can filter my form by either
choosing preset/sql filters from dropdown or just typing in date or text
It's all working fine except inconstant error - dont expect anyone to error
check this routine but I'm wondering if it can be simplified
Is it possible to search for dates and/or text is the same statement
Private Sub cboFILTERS_AfterUpdate()
On Error GoTo CantFilterForm
FilterOn = False
With cboFILTERS
If .ListIndex >= 0 Then Filter = .Column(1, .ListIndex): GoTo Inlist
'preset filter is fine
'Cant help but think the following could be simplyfied:
'---------------------------------------------------------------------------------
If IsDate(.Value) Then
Dim f As Long
f = CDate(.Value)
Filter = "[Enquired] = " & f _
& " or int([Booked]) = " & f _
& " or [invite sent] = " & f _
& " or [start date] = " & f _
& " or [DOB] = " & f _
& " or [Exit date] = " & f _
& " or [Job Outcome] = " & f
Else
Filter = "[first name] Like '*" & .Value & "*' or " _
& "[Last name] Like '*" & .Value & "*' or " _
& "[Address] Like '*" & .Value & "*' or " _
& "[town] Like '*" & .Value & "*' or " _
& "[A49] Like '*" & .Value & "*' or " _
& "[Interest] Like '*" & .Value & "*' or " _
& "[Ni NO] Like '*" & .Value & "*'"
End If
'------------------------------------------------------------------
End With
Inlist:
FilterOn = True
With RecordsetClone
.MoveLast
.MoveFirst
lblCount.Caption = "Record " & Me.CurrentRecord & " of " &
..RecordCount
If .RecordCount = 0 Then MsgBox "No Matches Found": FilterOn = False
End With
Exit_FilterForm:
Exit Sub
CantFilterForm:
MsgBox "Cant Filter Form: " & Err.Description
Resume Exit_FilterForm
End Sub
choosing preset/sql filters from dropdown or just typing in date or text
It's all working fine except inconstant error - dont expect anyone to error
check this routine but I'm wondering if it can be simplified
Is it possible to search for dates and/or text is the same statement
Private Sub cboFILTERS_AfterUpdate()
On Error GoTo CantFilterForm
FilterOn = False
With cboFILTERS
If .ListIndex >= 0 Then Filter = .Column(1, .ListIndex): GoTo Inlist
'preset filter is fine
'Cant help but think the following could be simplyfied:
'---------------------------------------------------------------------------------
If IsDate(.Value) Then
Dim f As Long
f = CDate(.Value)
Filter = "[Enquired] = " & f _
& " or int([Booked]) = " & f _
& " or [invite sent] = " & f _
& " or [start date] = " & f _
& " or [DOB] = " & f _
& " or [Exit date] = " & f _
& " or [Job Outcome] = " & f
Else
Filter = "[first name] Like '*" & .Value & "*' or " _
& "[Last name] Like '*" & .Value & "*' or " _
& "[Address] Like '*" & .Value & "*' or " _
& "[town] Like '*" & .Value & "*' or " _
& "[A49] Like '*" & .Value & "*' or " _
& "[Interest] Like '*" & .Value & "*' or " _
& "[Ni NO] Like '*" & .Value & "*'"
End If
'------------------------------------------------------------------
End With
Inlist:
FilterOn = True
With RecordsetClone
.MoveLast
.MoveFirst
lblCount.Caption = "Record " & Me.CurrentRecord & " of " &
..RecordCount
If .RecordCount = 0 Then MsgBox "No Matches Found": FilterOn = False
End With
Exit_FilterForm:
Exit Sub
CantFilterForm:
MsgBox "Cant Filter Form: " & Err.Description
Resume Exit_FilterForm
End Sub