By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,092 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

Filtering a query or report from user text input

P: 1
Hi!

In one of my tables I have an attribute called "descripton", which is a description of a particular item.

One example is
"Colonial cedar bookcase".

Is there anyway I can use user input to filter a query (or preferably a report using the "where" function in macros)? I want the user to be able to input "cedar" and have all records containing "cedar" in the descripton field appear.
Mar 11 '07 #1
Share this Question
Share on Google+
2 Replies


ADezii
Expert 5K+
P: 8,619
Hi!

In one of my tables I have an attribute called "descripton", which is a description of a particular item.

One example is
"Colonial cedar bookcase".

Is there anyway I can use user input to filter a query (or preferably a report using the "where" function in macros)? I want the user to be able to input "cedar" and have all records containing "cedar" in the descripton field appear.
__1. You cannot open a Query within a Macro and specify a WHERE Clause.
__2. You can open a Report within a Macro and specify a WHERE Clause in the following manner: [fieldname] = Forms![formname]![controlname on form]
__3. Why not create a Parameter Query and have the User set the criteria within the Query. e.g. in the Criteria cell of Description [Enter Description]. You can now run the Query from a Macro. You can also set the Record Source of a Report to this Query then open the Report from a Macro bypassing the WHERE Clause.
Mar 11 '07 #2

NeoPa
Expert Mod 15k+
P: 31,347
Hi!

In one of my tables I have an attribute called "descripton", which is a description of a particular item.

One example is
"Colonial cedar bookcase".

Is there anyway I can use user input to filter a query (or preferably a report using the "where" function in macros)? I want the user to be able to input "cedar" and have all records containing "cedar" in the descripton field appear.
When opening your form or report from your VBA code, simply specify a 'WhereCondition' argument :
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenReport("rptName",,,"[FieldName] Like '*cedar*'")
Mar 12 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.