Log in

View Full Version : Solved: forms and queries



goldie12
10-05-2005, 07:48 AM
Is it possible to create a form that will allow a user to perform their own queries? Basically I need some type of form where the user just clicks on certain criteria and performs queires and is able to present those results in a report. any suggestions?

chocobochick
10-05-2005, 10:12 AM
You can create a query to reference user input from a form's controls. So as long as the tables, join relationships, and selected fields are always the same, you can save a single query that can change depending on the user's input.

For example, say your form is named "frmSelectReport", which has a textbox named "txtLastName" where the user can specify which last name to search for. In your saved query, you would place the line [Forms]![frmSelectReport]![txtLastName] (with all brackets) in the Criteria box for the last name field. Then whenever the query is executed (whether by itself or for a form or report), it will use the value of the txtLastName textbox (provided that the form is opened) as its criteria.

goldie12
10-05-2005, 01:46 PM
You can create a query to reference user input from a form's controls. So as long as the tables, join relationships, and selected fields are always the same, you can save a single query that can change depending on the user's input.

For example, say your form is named "frmSelectReport", which has a textbox named "txtLastName" where the user can specify which last name to search for. In your saved query, you would place the line [Forms]![frmSelectReport]![txtLastName] (with all brackets) in the Criteria box for the last name field. Then whenever the query is executed (whether by itself or for a form or report), it will use the value of the txtLastName textbox (provided that the form is opened) as its criteria.

One more question. I get the following error message when I try and run my parameter query:

Invalid bracketing of name'[Forms]![Query]![StartDate] And [Forms]![Query]![EndDate]'.

Any suggestions?
Thanks for your help.

chocobochick
10-05-2005, 02:00 PM
You named your form "Query"? Try renaming it to something that might not be misinterpreted as a special keyword. I personally use the naming convention in which each form starts with the letters "frm", so in a case like this I might name it "frmUserQuery" or something similar.

Let me know if that doesn't solve the problem.

goldie12
10-06-2005, 06:15 AM
You named your form "Query"? Try renaming it to something that might not be misinterpreted as a special keyword. I personally use the naming convention in which each form starts with the letters "frm", so in a case like this I might name it "frmUserQuery" or something similar.

Let me know if that doesn't solve the problem.

I renamed it to Results and I still get the same error message. :banghead:

chocobochick
10-06-2005, 06:41 AM
That's an odd error. What version of Access are you using? What's the exact expression (all punctuation included) entered into your criteria box?

goldie12
10-06-2005, 12:59 PM
That's an odd error. What version of Access are you using? What's the exact expression (all punctuation included) entered into your criteria box?

It should be:



PARAMETERS [Forms]![Results]![CompanyName] Text ( 255 ), [Forms]![Results]![StartDate] DateTime, [Forms]![Results]![EndDate] DateTime;


as The operators Between and AND are not included in the parameter. It works fine now.

Thank you for your help!!!:thumb

xCav8r
10-09-2005, 08:20 PM
Goldie, if this is solved, would you mind using the Thread Tools at the top of this page to mark it solved? Thanks. ;)