filtering forms based on value in combobox

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Some help again please. I am stuck. I have gotten some help from the
newsgroup regarding filtering records in a form based on a value in a
combobox. I have tried this and it does not seem to work. I have created an
option group and applied the code below to the after update event and also
does not work

Private Sub FilteredRecords_AfterUpdate()
If FilteredRecords = 2 Then
Me.Filter = "DueDate = " & Format(Me.FindDate, "\#mm\/dd\/yyyy\#")
Me.FilterOn = True
Else
Me.FilterOn = False
End If
End Sub

where FilteredRecords in the name of the option group and FindDate is the
combobox. I have tried an option group with a field which is not a date
field and the result is the same, that is, 1 blank record. Am I missing
something here.
 
I'm not sure what the formatting should be on the date portion of it. That
part may be causing a problem. But i see a couple of other things you can do
to evaluate this thing. First, surround DueDate with brackets:
[DueDate]

And before you turn the filter on, give yourself a message box so you can see
what the filter is looking like:

MsgBox (Me.Filter)

If that MsgBox doesn't work, you may need to assign your statement to a
variable first:

Private Sub FilteredRecords_AfterUpdate()
If FilteredRecords = 2 Then
Dim strFilter as String
strFilter = "[DueDate]= " & Format(Me.FindDate, "\#mm\/dd\/yyyy\#")
MsgBox strFilter
Me.Filter = strFilter
Me.FilterOn = True
Else
Me.FilterOn = False
End If
End Sub
 
Thanks HK, the message box part really helped me to understand what was
going wrong. The filter works fine now
 
Back
Top