473,394 Members | 2,160 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,394 software developers and data experts.

Create a multiple parameter search form for a query

I need to figure out how to create a user interface to search a query,
but here's the bad part...I need to account for criteria on at least 7
of the fields. Here's what I'm thinking I need to do:

Create an unbound form with unbound fields for all 7 of the fields in
the query. Then in the query create parameters that refer to those
fields.

But it's not that simple because the user needs the flexibility of
filling in as many or as few of the fields as they want. For example,
they may have "account number", a "customer agent number" and a "date
opened" and an "account type" to search by, or maybe they want to see
all accounts of a certain type only.

Is there any easier way to do this? All I can picture is writing lines
and lines of criteria for all the combinations of "ANDs" and/or "ORs"
that this would require. If there's a different road to go down, in VB
or something, I'm all for it, anything that could be cleaner than
this...

Jun 30 '06 #1
2 9415
"angie" <ub*******@hotmail.com> wrote in
news:11**********************@m73g2000cwd.googlegr oups.com:
I need to figure out how to create a user interface to search
a query, but here's the bad part...I need to account for
criteria on at least 7 of the fields. Here's what I'm
thinking I need to do:

Create an unbound form with unbound fields for all 7 of the
fields in the query. Then in the query create parameters that
refer to those fields.

But it's not that simple because the user needs the
flexibility of filling in as many or as few of the fields as
they want. For example, they may have "account number", a
"customer agent number" and a "date opened" and an "account
type" to search by, or maybe they want to see all accounts of
a certain type only.

Is there any easier way to do this? All I can picture is
writing lines and lines of criteria for all the combinations
of "ANDs" and/or "ORs" that this would require. If there's a
different road to go down, in VB or something, I'm all for it,
anything that could be cleaner than this...

Do you need to filter the query, or can you filter the
form/report which has the query as a recordsource?

If you can, it's easier.

Either way, build an unbound form with the controls, And/Or
selectors and a "Do It" button.
In the OnClick Event for the button, build a SQL where clause
based on the contents of the fields and the setting of the AndOr
selectors.

Dim strWhere as string
If len(me.txtLastname) & "" > 0 then
strWhere = strWhere & iif(me.Andor1 = "And", " and ", " OR
")
strWhere = strWhere & "[table].[lastname] = """ & txtLastname
& """"
end if
If len(me.txtFirstname) & "" > 0 then
strWhere = strWhere & iif(me.Andor1 = "And", " and ", " OR
")
strWhere = strWhere & "[table].[Firsttname] = """ &
txtFirstname & """"
end if

.....
' when done strip off the first and /or
strWhere = mid(strWhere,5)

'If you are opening a form or report, just pass the whereclause
as a parameter in the relevant
DoCmd.Openform "formname",,,strWhere

If it's a query you have to create a recordset and muck around
with the full SQL string. How this is done depends on how you
want to use the query, ask if you need to.

--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Jun 30 '06 #2
On your Prompts form, you should have a [Submit] button that will have
an On-click event to hold some VBA code.

Dim qd As DAO.QueryDef
Dim Whereclause As String
Dim ssql As String
Dim Assignment As Integer

ssql = "SELECT * From table"

IF me!AccountNumber Not NULL Then
Whereclause = " WHERE AccountNumber = " & Me!AccountNumber
End If

IF CustomerAgent Not NULL then
IF Whereclause is NULL Then
whereclause = " WHERE CustomerAgent = " & me!CustomerAgent
Else
Whereclause = " AND CustomerAgent = " & me!CustomerAgent
End IF
END IF

' Make IF statements for each field on the Prompts form.
' At the end you will have a Whereclause that has entries for those
fields that were filled in; or possibly Whereclause will be NULL.

IF Whereclause Not NULL then
ssql = ssql & Whereclause
End IF

'Then execute the ssql or save it as a query and then do whatever other
VBA code you want.

Jun 30 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Ed_No_Spam_Please_Weber | last post by:
Hello All & Thanks in advance for your help! Background: 1) tblT_Documents is the primary parent transaction table that has 10 fields and about 250,000 rows 2) There are 9 child tables with...
2
by: dskillingstad | last post by:
I'm trying to set up a parameter query based on an unbound form. This search form has about 5 text boxes where the user can type in values within each box and search a specific table based on the...
4
by: Dave Edwards | last post by:
I understand that I can fill a datagrid with multiple queries, but I cannot figure out how to fill a dataset with the same query but run against multiple SQL servers, the query , table structure...
3
by: RoadRunner | last post by:
I have a form that has 6 command buttons on it. Each command button runs a different query with a wildcard parameter value that looks in 6 different tables in 6 different linked databases. None...
9
by: lightning | last post by:
Hi all, I'm not very conversant with the vocabulary of Access, so please ask for clarification if necessary... I am trying to build a search form that allows combinations of search terms. For...
1
by: almu | last post by:
Hi all, I need help to build a set of queries in PHP/MySQL for a multiple-parameter search form, whereby the user will be able to search any number of ways (upto seven) Thanks
6
by: Dave | last post by:
On my form I have combo boxes. These combo boxes, after updating them, populate respective listboxes that are located below the combo boxes on the same form. I am trying to use a "generate...
3
by: vljones | last post by:
I am either having an extended blond moment or have been looking at this too long. This is a basic question but I simply cannot get my head around the solution. I have a Search form with grouped...
18
by: sweeneye | last post by:
Hi, I'm basing a query on the variables used in a form. The database contains lots of problems, say with a computer and a tick box for the apropriate component like monitor, keyboard, mouse etc....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.