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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

queries with many parameters

Status
Not open for further replies.

Joels7

MIS
May 1, 2001
9
US
I want to set up a form based on a query; The user will be able to enter values on the form for the fields of his choice, and return the records with matching values.

How can I implement without having all the boxes flashing one at a time (I want to enter any/all values in the query itself.

Thank you,

Joels7
 
You can build the query in VBA code using the fields on your form.

For example, let's say you have a simple form with 4 text boxes that the users can enter info into, (Type, Color, Begin Date and End Date)

The form probably also has a command button for the user to click when he is done entering data and ready to retrieve the records. On the click event of the button, you need the following code:

Dim Criteria as string
Const dquote """" 'yes that's 4 double quotes not a typo

Criteria = ""
If not(isnull(me!type)) then
Criteria = " where type = " & me!type
end if

If not(isnull(me!color)) then
if Criteria = "" then Criteria = " where "
Criteria = Criteria & "color = " dquote & me!color & dquote
end if

If not(isnull(me!begdate)) then
if Criteria = "" then Criteria = " where "
Criteria = Criteria & "BegDate >= #" & me!begdate & "#"
end if

If not(isnull(me!enddate)) then
if Criteria = "" then Criteria = " where "
Criteria = Criteria & &quot;EndDate <= #&quot; & me!enddate & &quot;#&quot;
end if

docmd.openform &quot;formname showing records&quot;,,,criteria


Just customize the above code to meet your needs. Maq B-)
<insert witty signature here>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top