how create a button that filter by preset value?

laghetto

Registered User.
Local time
Yesterday, 22:31
Joined
Aug 20, 2011
Messages
27
Hi,
i need your help:
i'm creating a weekly planner.
I have a form for insert events and their date and set an argument (a, s, a+s)
and a mask who shows a little form for every day of the week.
i need to create a button (or some other control field) that permit me to filter by argument: eg i press on the "filter by A" and it show me only records that have the field A selected, the same for S, A+S and for "none".
the filter has to be maintained also if I select another week, month or year using the buttons.
M_tab_promemoria: is the form for insert new event and select the argument
Maschera1: is the form with the view of planner (note: i'm not really smart so i created 1 query and 1 form for every day)
query_settimanale1_LUN: is the form for monday (and i used the same name for the query)

The buttons for filter by A and by S that i have let in the Maschera1 form do not work (i tryed in some way but let them void to make more simply explain what i need... i hope)

thank you in advance.
PS i use access2003
 

Attachments

If your recordsets are small, using the form filter works fine. I add two buttons to my forms when working with multiple field filters - Clear Filter and Apply Filter.
the Clear Filter button resets all the filter fields to null and sets the filter off -
Me.FilterOn = False
The Apply Filter creates a string combining the selections and then sets the filter on
Me.Filter = strFilter
Me.FilterOn = True

Here's a small example of how you might construct the filter:

Code:
If IsDate(Me.FromDate) Then
    If IsDate(Me.ThroughDate) Then
         strFilter = "MyDate Between " & me.FromDate & " AND " & Me.ThroughDate
    Else
         strFilter = "MyDate >= " & Me.FromDate
    End IF
Else
    If IsDate(Me.ThroughDate) Then
        strFilter = "MyDate <= " & Me.ThroughDate
    End If
End If
If Me.City & "" <> "" Then
    If strFilter = "" Then
        strFilter = "City = """ & Me.City & """"         'city names may contain single quotes so you need to enclose the string in double quotes
    Else
        strFilter = strFilter & " AND City = """ & Me.City & """"
    End If
End If
 

Users who are viewing this thread

Back
Top Bottom