Use a command button to run a query and open form

Johnny Drama

In need of beer...
Local time
Today, 13:06
Joined
Dec 12, 2008
Messages
211
Is it possible to open a form using a command button and having that command button pass the query criteria as well, ie, When you click the button, it opens a form and provides the query criteria to the underlying query as well. The query criteria would be fixed; the user would not need to input anything as it would be coded into the command button code. I can't figure out how to code this, if it's even possible.
 
the docmd.openform holds the secrets you are looking for ...

Simply use the WHERE part with the query as recordsource to the form, should work perfectly
 
Care to provide an example? What I have is:

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmTesting"
stLinkCriteria = "[Category]= Financial"
DoCmd.OpenForm stDocName, , , stLinkCriteria

What happens presently is a critera box will open asking for a critera and is labeled "financial", if I enter "Financial" as the criteria the form will open but the criteria is not passed to the query. The whole idea is that a criteria box will not even open, the criteria is hardcoded in the command button.
 
If you want a literal string, tell access it is one...

stLinkCriteria = "[Category]= 'Financial' "
or
stLinkCriteria = "[Category]= ""Financial"" "
 

Users who are viewing this thread

Back
Top Bottom