VB COde for invoking Filter By Form from Button

I have a simple form with a number of fields. I want to add a button on the form so that it wil invoke the Filter By Form function. Or is there an easier way to build search forms? I don't mind allowing the user to search for all items on the form.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

once you have the filter built...
me.filter = "MyField = 'MyValue'"
jcaiolaAuthor Commented:
I have a form called "Home"
On this form are four fields: "Name", "Number", "City", "Zip"
I want to click a button on that form and have it bring back the same 'form', but as a search form with all of the fields blank.
To have a command button invoke the filter by for you use

DoCmd.RunCommand acCmdFilterByForm

Cheers, Andrew

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Newly released Acronis True Image 2019

In announcing the release of the 15th Anniversary Edition of Acronis True Image 2019, the company revealed that its artificial intelligence-based anti-ransomware technology – stopped more than 200,000 ransomware attacks on 150,000 customers last year.

jcaiolaAuthor Commented:
Thanks - this should do the trick.

One final question. If I want to use a command button to jump to a form with a subset of the larger form's fields, search and then come back to the original form with the found record selected, do I just do this by creating a small form, opening it as a popup, searching for the appropriate record, and then closing it?
That is a major piece of VBA coding and you are on the right lines with the logic.
Cheers, Andrew
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
"I want to add a button on the form"
Why not user the built in right click menus ... OR .. easily build your own professional looking menus/toolbars.

Everything you need is here ... see this link:

Not sure it that article mentions it, but ... when you are in the Customize mode (dialog) ... if you hold down the Control key, you can drop and drag (ie, copy) menu items from one place to another ... handy for making a new menu that is similar another one.

Here is a related link also:


It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.