Filter Button

A

Antonio

This is in regards to an earlier posting dated 30 May
2004.
I had asked if it was possible to create a "Filter By
Selection" and "Filter Off" buttons on a form. John
Vinson stated that it was possible if I created a
continuous form. I did so, but have been unsuccessful at
finding and example of the type of "Filter Buttons" I
described above.
Can anyone give me an example of the code required behind
the "On Click" event of the button that would Filter the
records based on the data field the user has currently
highlighted? (also, the code required to remove such a
filter)
TIA

Copy of previous posting:

Subject: Re: Filter by selection
From: "John Vinson"
<jvinson@STOP_SPAM.WysardOfInfo.com> Sent: 6/3/2004
1:02:43 PM

I have a form that displays several records in Datasheet
form. On the form header I would like to place to
buttons. The first would "Filter By Selection" and the
second would "Remove Filter". I know this can be done by
righ mouse clicking, but I removed those options when the
database starts up (a customer request). Now, they still
want to be able to filter by selections, but with an on
and off button on the form. Is this possible?
TIA

Not, to my knowledge, on a Datasheet; but you can create
a Continuous
form which looks just like a datasheet and gives you a
form header in
which you can put such buttons.


..
 
V

Van T. Dinh

DoCmd.RunCommand acCmdFilterBySelection

for the first CommandButton_Click Event and

DoCmd.RunCommand acCmdRemoveFilterSort

for the 2nd CommandButton_Click Event.

--
HTH
Van T. Dinh
MVP (Access)
 
A

Antonio

I placed a button on the Form Header and pasted the code
into its click event. After I compiled, saved, and opend
the form...I highlighted one of the data fields and got
the following error:

Run Time Error "2046"
The Command or Action "FilterBySelection" isn't available
now.

I'm not sure what I am doing wrong.
TIA
 
V

Van T. Dinh

You need to set the Focus to the relevant Control before filtering. Add

Screen.PreviousControl.SetFocus

before the DoCmd statement.
 

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