Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing multiple parameters from Access form to query

Status
Not open for further replies.

jcaulder

Programmer
Apr 22, 2002
241
US
I am attempting to pass multiple parameters from an Access form to a predesigned query that was also built in Access. The basic idea is that I want to allow the user to enter various query criteria via the form then use those values in the WHERE clause of the query. I do not want to create the query in code using recordset objects. I want to use the query design aspect of Access to build the query. From much trial and error, I have determined that Access seems to only allow the object with current focus on the form to pass its value to the query. So if I have two text box values I want to pass a query, only the value with the focus gets sent, the other apparently sends NULL.

Example:
form1.text1.setfocus
form1.text1.text = 04/22/02
form1.text2.setfocus
form1.text2.text = 04/23/02
docmd.openquery("queryname")

***the query, as stated above is already created in Access
***the WHERE clause is basically like the following. . .
WHERE order_date >= form1.text1.text AND order_date<form1.text2.text

In this example because text1 no longer has the focus, the query pulls in NULL for this value whereas the text2 pulls in 04/23/02.

Is there anyway to pass multiple values from an Access form to an Access query?

TIA!!
 
Just set up the query object so that the criteria refer to specific controls on the form. When the query is called from the active form, it will see the data in the fields and complete the action.

example:

SELECT * From myTable WHERE (((Date1)=[Forms]![form1]![text2]));
petersdaniel@hotmail.com
&quot;If A equals success, then the formula is: A=X+Y+Z. X is work. Y is play. Z is keep your mouth shut.&quot; --Albert Einstein

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top