Filter by Form as a Command Button

G

Guest

I am still not getting this... I have created a form which shows in Rows
multiple records...the records are each dated as to when it was entered which
could be several daily... General users do not not how to properly use the
"Filter by Form" button; therefore, I am trying to create a Command Button or
Calendar so users can simple filter the records by dates. When I created the
Filter Command Button on the form, it will not allow anyone to choose a date;
instead, it simply automatecally filters by the first record date. what am I
doing wrong here? There has to be a way to create a Filter Command Button
that works or even a Calendar so users can simple choose a date and click on
filter. Am I making sense here? Please help anyone.
 
M

MacDermott

You can put a button on your form which will emulate the FilterByForm menu
button; use this code:
DoCmd.RunCommand acCmdFilterByForm
However, when the form is in FilterByForm mode, all buttons on it are
de-activated, so you can't supply your users with another button on the form
to apply the filter.
My best suggestion is to go ahead and teach your users to use Filter By Form
from the menu; it's so handy, and they can use it in many places - even in
other Access databases.
 
A

Allen Browne

Place an unbound text box in the Form Header section of your continuous
form, and give it these properties:
Name txtFilterDate
Format Short Date
After Update [Event Procedure]

Then click the Build button (...) beside the AfterUpdate property, and set
up the event procedure like this:

Private Sub txtFilterDate_AfterUpdate()
Dim strWhere As String
If Me.Dirty Then
Me.Dirty= False
End If
If IsNull(Me.txtFilterDate) Then
Me.FilterOn = False
Else
strWhere = "[YourDateFieldNameHere] = " & Format(Me.txtFilterDate,
"\#mm\/dd\/yyyy\#")
Me.Filter = strWhere
Me.FilterOn = True
End If
End Sub

If you prefer, use the Click event of a command button instead of the
AfterUpdate event of the text box.

If you want to use 2 text boxes for a date range, build the strWhere string
as in this example:
http://allenbrowne.com/casu-08.html

If you want to use a calendar instead of a text box:
http://allenbrowne.com/ser-51.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top