I’ve been trying to add the menu command, Filter by Form, to a custom button on a form I’m creating in an MS Access database.
I’ve tried searching all of the help files on DoCmd, DoMenuItem etc. and I just can’t seem to find the right way to do this.
Any Ideas? As usual any and all help is greatly appreciated!
You can add a button that run the following code:
DoCmd.DoMenuItem acFormBar, acRecordsMenu, 0, 3, acMenuVer70
This starts the filter but unfortunately, the built-in form stuff kicks in and you have to use the tool bars to apply, or cancel the filter.
K364,
Thanks for the help!
I have 2 books on Access 2000 and neither one lists the arguments to be used in the DoMenuItem action.
Do you know of a good refrence for DoMenuItem and/or DoCmd?
Thanks Again!
Wait a minute. That wasn’t my Final Answer!
I too am using Access 2000…
To “solve” your problem, I added a button with wizardry turned on. The Command Button Wizard popped up and I chose “Form Operations” and then “Edit Form Filter”.
Unfortunately that gave me the advanced filter. There didn’t seem to be any other options with the wizard. So I looked at the code it produced and changed “…acRecordsMenu, 0, 2,…” to “…acRecordsMenu, 0, 3,…” (this was pure guesswork)
To answer your question about a reference, I went into Access Help and found that the “DoMenuItem” has been superceded by “RunCommand” (why the Wizard inserts obsolete code is one of Microsoft’s little mysteries)
Anyway, your code should be:
DoCmd.RunCommand acCmdFilterByForm
These “RunCommand Method Constants” are in the Access Help. Other than that, I don’t know of any other reference. Anybody else?