Filtering a form by user-selected date

  • Thread starter Thread starter Wytze
  • Start date Start date
W

Wytze

Hi,

I'm having problems with a form for registering worktime activities. A
user can enter several activities on the same date. In a form, I want
the user to be able to pick a date from a list, with the result that
only activities assigned to that date are shown.

Whatever I try, using DoCmd.ApplyFilter always has the same effect:
only the 'new record' is shown.

What do I have to do?

With kind regards,

Wytze
 
Start with a form bound to the table in the normal way. In design view add
an unbound combo box or list box to the form so that it lists all dates from
the table by means of a RowSource property along these lines:

SELECT DISTINCT [YourDateField]
FROM [YourTable]
ORDER BY [YourDateField];

In the AfterUpdate event procedure of the combo or list box put code like
this:

Me.Filter = "[YourDateField] = #" & Format(Me.[YourListBox],"mm/dd/yyyy") &
"#"
Me.FilterOn = True

If you want a 'Show All' button on the form to clear the filter then the
code for its Click event procedure would be:

Me.FilterOn = False

Ken Sheridan
Stafford, England
 
Back
Top