473,386 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Passing Query parameters through a Form

hyperpau
184 Expert 100+
Hi there guys!

I have a Form where there are three comboboxes. This comboboxes are used as references for the parameter of 3 fields in a query. when I hit a command button in my form, it opens a query with the parameters selected from the form.

Let's say I have three fields in my query. [Description],[Status], and [Location]
On the design view of the query, I put these criterias on different lines so that it would be using the OR:

[Description]
=[Forms]![frmMyForm]![cboDescription]

[Status]
=[Forms]![frmMyForm]![cboStatus]

[Location]
=[Forms]![frmMyForm]![cboLocation]


This works fine even if I leave the other combo boxes in my form as blank. But the Problem is, if a make a selection for all combo boxes in my form, my query shows all the records with matching results from the different fields.

What I want to do is that when selections are made to all three comboboxes, the query would only show records that matches all the fields.

I tried putting all the criterias of the query on just one line. But then it would not show any records if no selection is made on any one of the comboboxes.

Can any one help me on this?

What I want is that, when I only make a selection to only one combo box, then the query results will give me all records that matches that combo box.
But If I make selection to more than one combo box, then it should give me results with both fields matching the parameters passed over by the comboboxes.

Meaning:
If only one combo box is changed, the parameters would be using OR
If two or all combo boxes are changed, the parameters would be using AND
Aug 2 '07 #1
3 2673
Rabbit
12,516 Expert Mod 8TB
Expr1: Nz(FieldName, "")
=Like "*" & Forms!FormName!cboName & "*"

Use AND instead of OR
Aug 2 '07 #2
The SQL should be:

SELECT * FROM tblTable WHERE [Description]=Me.cboDescription AND [Status]=Me.cboStatus AND [Location]=Me.cboLocation

Because the conditions are joined by ANDs, only the records that match all three conditions will be displayed. Now, if you are displaying the information with a form or report, place this is the WHERE portion of the DoCmd:

"WHERE [Description]=' " & Me.cboDescription & " ' AND [Status]=' " & Me.cboStatus & " ' AND [Location]=' " & Me.cboLocation & " ' "

(I have assumed that the values are text and not numeric for the combo boxes. If the values are numeric, you can drop the " ' "s. Example: " AND [Location]=" & Me.cboLocation.


Hi there guys!

I have a Form where there are three comboboxes. This comboboxes are used as references for the parameter of 3 fields in a query. when I hit a command button in my form, it opens a query with the parameters selected from the form.

Let's say I have three fields in my query. [Description],[Status], and [Location]
On the design view of the query, I put these criterias on different lines so that it would be using the OR:

[Description]
=[Forms]![frmMyForm]![cboDescription]

[Status]
=[Forms]![frmMyForm]![cboStatus]

[Location]
=[Forms]![frmMyForm]![cboLocation]


This works fine even if I leave the other combo boxes in my form as blank. But the Problem is, if a make a selection for all combo boxes in my form, my query shows all the records with matching results from the different fields.

What I want to do is that when selections are made to all three comboboxes, the query would only show records that matches all the fields.

I tried putting all the criterias of the query on just one line. But then it would not show any records if no selection is made on any one of the comboboxes.

Can any one help me on this?

What I want is that, when I only make a selection to only one combo box, then the query results will give me all records that matches that combo box.
But If I make selection to more than one combo box, then it should give me results with both fields matching the parameters passed over by the comboboxes.

Meaning:
If only one combo box is changed, the parameters would be using OR
If two or all combo boxes are changed, the parameters would be using AND
Aug 2 '07 #3
hyperpau
184 Expert 100+
Expr1: Nz(FieldName, "")
=Like "*" & Forms!FormName!cboName & "*"

Use AND instead of OR
This works perfectly. Thanks.
Sep 18 '07 #4

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

Similar topics

1
by: Mike Wimpe | last post by:
Without creating a form, how do i pass a value to another script? I would like to pass: group = "Oranges" to another script or at least just 'group' and initialize it in the first script. ...
1
by: Michael DeLawter | last post by:
Using Access 2002. I have a chart in a report that is currently based on a query in which the user enters the start and end date for the chart to display. Both the start and end dates have been...
3
by: MX1 | last post by:
I'm ready to pull the hair out of my head. I have a query with a couple of parameters that I want to get from combo boxes on a form. One parameter is a date with a dynamically calculated year and...
4
by: Greg Iocco | last post by:
Simple problem, but I've checked the newsgroups and couldn't find an answer. On the main swithboard is a command button to open a report. The report I built is based off a query, and the query...
1
by: bentond | last post by:
I am trying to write a simple form that allows a user to search through an address table. The main form has the text boxes (to be used as where parameters) and when clicking the search button will...
0
by: Zlatko Matić | last post by:
Hi everybody! Recently I was struggling with client/server issues in MS Access/PostgreSQL combination. Although Access is intuitive and easy to use desktop database solution, many problems...
39
by: Mike MacSween | last post by:
Just spent a happy 10 mins trying to understand a function I wrote sometime ago. Then remembered that arguments are passed by reference, by default. Does the fact that this slowed me down...
11
by: kennthompson | last post by:
Trouble passing mysql table name in php. If I use an existing table name already defined everything works fine as the following script illustrates. <?php function fms_get_info() { $result =...
3
by: RoadRunner | last post by:
Hi, I am having a problem. I have a very simple employee database. The client needs to see everything on a form before any updates or deletions can be made. I have a form that loads with two...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.