using form for filter

  • Thread starter Thread starter Stefan
  • Start date Start date
S

Stefan

I am opening a report from an unbound form. I have two
unbound fields for the filter.

DateFrom and DateTo.
If these fields are left blank I would like to return all
values.
If only DateFrom is completed I would like it to filter
from that date forward.
If only DateTo is completed I would like it to filter up
to that date.
If both fields are completed I would like to filter
between these dates.

I have a command button to open the report.

Could somebody help me with the vba code to do the
filtering.

Thanks in advance.
 
Use a critieria expression similar to the following for your date field in
the query:

Between Nz([Forms]![FormName]![DateFrom],#1/1/1900#) And
Nz([Forms]![FormName]![DateTo],Date())

Replace FormName with the actual name of your form.
 
Back
Top