C
Chad Lupkes
I have the following code behind a simple form:
----
Option Compare Database
Private Sub B_Clear_Click()
'remove all filters
Me!cboStoreNumber = Null
Me!cboDeptNumber = Null
Me!cboPONumber = Null
' call filter procedure
ApplyFilter
End Sub
Private Sub cboStoreNumber_AfterUpdate()
ApplyFilter
End Sub
Private Sub cboDeptNumber_AfterUpdate()
ApplyFilter
End Sub
Private Sub cboPONumber_AfterUpdate()
ApplyFilter
End Sub
Private Sub ApplyFilter()
Dim strFilter As String
strFilter = "1=1 "
' filter by Store Number?
If Not IsNull(Me!cboStoreNumber) Then
' add groupname filter
' strFilter = strFilter & " AND [Store] = '" & Me!
cboStoreNumber & "'"
strFilter = strFilter & " AND [Store] = " & Me!cboStoreNumber
& ""
End If
' filter by Dept Number?
If Not IsNull(Me!cboDeptNumber) Then
strFilter = strFilter & " AND [Dept] = " & CStr(Me!
cboDeptNumber)
End If
' filter by PO Number?
If Not IsNull(Me!cboPONumber) Then
strFilter = strFilter & " AND [PONumber] = '" & CStr(Me!
cboPONumber) & "'"
End If
' apply filter
Me.Filter = strFilter
' set filtering on
Me.FilterOn = True
End Sub
----
I'm trying to apply the filter to a date field, and it's giving me
trouble. I found the following syntax somewhere else:
If Not IsNull(Me!txtStartDate) Then
strFilter = strFilter & " And [DateField >= #" & _
Me!txtStartDate & "# "
End If
I tried this with my variables, and it didn't work. It will select a
date from the combo box, but will not filter the records on the form
itself.
So, my questions are:
1. What syntax would work better than the date example above?
2. How can I also filter by a checkbox (Yes/No)
I look forward to your reply.
----
Option Compare Database
Private Sub B_Clear_Click()
'remove all filters
Me!cboStoreNumber = Null
Me!cboDeptNumber = Null
Me!cboPONumber = Null
' call filter procedure
ApplyFilter
End Sub
Private Sub cboStoreNumber_AfterUpdate()
ApplyFilter
End Sub
Private Sub cboDeptNumber_AfterUpdate()
ApplyFilter
End Sub
Private Sub cboPONumber_AfterUpdate()
ApplyFilter
End Sub
Private Sub ApplyFilter()
Dim strFilter As String
strFilter = "1=1 "
' filter by Store Number?
If Not IsNull(Me!cboStoreNumber) Then
' add groupname filter
' strFilter = strFilter & " AND [Store] = '" & Me!
cboStoreNumber & "'"
strFilter = strFilter & " AND [Store] = " & Me!cboStoreNumber
& ""
End If
' filter by Dept Number?
If Not IsNull(Me!cboDeptNumber) Then
strFilter = strFilter & " AND [Dept] = " & CStr(Me!
cboDeptNumber)
End If
' filter by PO Number?
If Not IsNull(Me!cboPONumber) Then
strFilter = strFilter & " AND [PONumber] = '" & CStr(Me!
cboPONumber) & "'"
End If
' apply filter
Me.Filter = strFilter
' set filtering on
Me.FilterOn = True
End Sub
----
I'm trying to apply the filter to a date field, and it's giving me
trouble. I found the following syntax somewhere else:
If Not IsNull(Me!txtStartDate) Then
strFilter = strFilter & " And [DateField >= #" & _
Me!txtStartDate & "# "
End If
I tried this with my variables, and it didn't work. It will select a
date from the combo box, but will not filter the records on the form
itself.
So, my questions are:
1. What syntax would work better than the date example above?
2. How can I also filter by a checkbox (Yes/No)
I look forward to your reply.