473,594 Members | 2,756 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

query by form

I am trying to build a form that has certain criteria on it (combo
boxes) which a user can pick from a range of values to specify the
criteria he wants when he runs a query on the form. I am trying out
different ways to do this, but nothing is working. Does anyone know
the easiest way to do this?
Nov 13 '05 #1
3 6375
It would be pretentious to say that this is the *best* way, but here's a
simplified example:

Two comboboxes, with:
cboCity.rowsour ce = "SELECT city FROM lu_city_table"
cboState.rowsou rce = "SELECT state FROM lu_state_table"

When you click your query button:

lstResults.rows ource = "SELECT add_house, add_street, add_apt, add_city,
add_state, add_zip FROM address WHERE add_city = ' " & Me.cboCity & " ' AND
add_state = ' " & Me.cboState & " ' "

lstResults.requ ery
Darryl Kerkeslager
"Matthew" <ma************ @eaton.com> wrote in message
news:7f******** *************** ***@posting.goo gle.com...
I am trying to build a form that has certain criteria on it (combo
boxes) which a user can pick from a range of values to specify the
criteria he wants when he runs a query on the form. I am trying out
different ways to do this, but nothing is working. Does anyone know
the easiest way to do this?

Nov 13 '05 #2
I'm not sure if you are trying to write a Query By Form solution.

If you are, I have seen a good textbook solution. It used checkboxes
down the left side of the form and choices to the right of them.

For example, to the right of checkbox 1, you might have a combo box
where the user can select a single value. To the right of checkbox 2,
you might have two textboxes where the user can enter a From date and
a To date.

By default, the checkboxes down the left are enabled and the choices
down the right are disabled.

When the user selects a checkbox, its After_Update event handler
enables the choice to its right, so the user can now make a selection
or enter a value.

And vice versa, if the user then deselects the checkbox, the
After_Update event handler disables the choice to the right.

So the After_Update event handler would contain code like:
Me.cboChoice1.E nabled = (Me.chkChoice1= True)
or (same thing):
Me.cboChoice1.E nabled = Me.chkChoice1
or
Me.txtFromDate. Enabled = Me.chkChoice2
Me.txtToDate.En abled = Me.chkChoice2

Presumably, you have a command button on the form to signal the user
has made all necessary choices. This button's Click event handler
should check which checkboxes are true and build an SQL statement
accordingly from the appropriate combo selections or textbox entries.
Then you can run or use the SQL statement.

There a numerous possibilities, but in principle that's how it could
be done.

As I said at the beginning, I realise your question could be
interpreted at meaning something quite different, but hope this was
your intended meaning.

Geoff

"Matthew" <ma************ @eaton.com> wrote in message
news:7f******** *************** ***@posting.goo gle.com...
I am trying to build a form that has certain criteria on it (combo
boxes) which a user can pick from a range of values to specify the
criteria he wants when he runs a query on the form. I am trying out
different ways to do this, but nothing is working. Does anyone know
the easiest way to do this?

Nov 13 '05 #3
If there are several criteria and they are not always used, I like to
construct a Where string and then use that string in opening the query, form
or report for which the criteria apply. I usually use a user-defined
function like GeteWhereString () to return the string:

-----------------

GetWhereString( ) as String

Dim strWhere as String

strWhere = vbNullString

' FIRST NAME
If Not IsNull(Me!txtPe rsFirstName) Then
strWhere = strWhere & " AND [PersFirstName] Like " & Chr(34) &
Me![txtPersFirstNam e] & Chr(34)
End If

' LAST NAME
If Not IsNull(Me!txtPe rsLastName) Then
strWhere = strWhere & " AND [PersLastName] Like " & Chr(34) &
Me![txtPersLastName] & Chr(34)
End If

' STREET NAME
If Not IsNull(Me!txtPe rsStreetAddress ) Then
strWhere = strWhere & " AND [PersStreetAddre ss] Like " & Chr(34)
& Me![txtPersStreetAd dress] & Chr(34)
End If

' CITY
If Not IsNull(Me!txtPe rsCity) Then
strWhere = strWhere & " AND [PersCity] Like " & Chr(34) &
Me![txtPersCity] & Chr(34)
End If

If strWhere <> vbNullString then strWhere = Mid(strWhere,6) ' remove
initial " AND "

GetWhereString = strWhere

--------------

In the example above, if the user supplies criteria for any of the items
listed, they will be included in the Where string. If the user leaves some
out (no First Name, for example) the Where string simply ignores that field.
Using "Like" enables the user to use wild cards; the Chr(34)s are just text
delimiters.

This would be used in opening a form like this, assuming the form is
based on a table or query that includes the required fields.

DoCmd.OpenForm "MyForm", , , GetWhereString

If you want to use it with a query, you have to modify the querydef's
SQL property, so it's probably simpler to create a separate form in
datasheet view and open that.

"Matthew" <ma************ @eaton.com> wrote in message
news:7f******** *************** ***@posting.goo gle.com...
I am trying to build a form that has certain criteria on it (combo
boxes) which a user can pick from a range of values to specify the
criteria he wants when he runs a query on the form. I am trying out
different ways to do this, but nothing is working. Does anyone know
the easiest way to do this?

Nov 13 '05 #4

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

Similar topics

3
5380
by: Harvey | last post by:
Hi, I try to write an asp query form that lets client search any text-string and display all pages in my web server that contain the text. I have IIS 6.0 on a server 2003. The MSDN site says there is a sample file called Ixtrasp.asp, but I could not find it in my system although I installed indexing service. I followed the steps in MSDN site to create a basic .asp query form (too long to post it here), but it always displays: No...
3
29005
by: MX1 | last post by:
I have a query written in MS Access that has a few calculated fields. Is it possible to refer to that query in a form field. I'd like the form field to show the sum of one of the columns from the query I've written. I've tried to put the following in the form field's control source property but I'm getting an error. Query1 is the name of the query and CalculatedTotal is the calc'd field column I'm trying to get a total for in the form...
3
4974
by: Steve | last post by:
Form FrmRestock's recordsource is QryFrmRestock. The TransactionDate field's criteria is set ats: Forms!FrmRestock!LastXDays. LastXDays on the form is a combobox where the selections are 30, 60 and 90. The default is set at 30. Question1: When the form opens, there are no records displayed although there are many records that fit the criteria of 30. If I put a button on the form to do a requery and press the button, all the records...
1
3079
by: Nicolae Fieraru | last post by:
Hi All, I want to find if there is a different way than the way I am working now. Lets say I have a table, tblCustomers containing address details. I want a report with all the customers from a specific state. In order to generate that, I create a form, I put a combobox with the states and a Command Button which opens a report. The report is based on a query, qryCustomersByState which has a parameter (State) taken from the Form.
6
17144
by: Brian | last post by:
Hello, Basically, I'm running a query on a form's activation, and I'd like to have the results of the query be placed into other fields on the same form automatically. Does anybody know how this can be done? I've tried setting the default value of the text fields on the form to be equal to ! using Access' expression
13
4219
by: Lee | last post by:
Hello All, First of all I would like to say thank you for all of the help I have received here. I have been teaching myself Access for about 4 years now and I've always been able to find a solution here - until now. This one is driving me crazy. I am making my first attempt at creating a runtime application. I am using Access 2003 Developer Extensions. Initially I developed the database without planning on creating a runtime app...
3
3504
by: rhobson2 | last post by:
Hello, I wrote a database applicaiton using Access XP (2002) and everything has been working good for the client until they purchased a couple of new computers with Access 2003. The meetings form has an unbound combo box listing all the meetings in the database allowing the user to navigate between meeting records. The meetings form also has a list box that displays a list of members associated with a meeting.
1
2672
by: bgreenspan | last post by:
Hi Everyone, I'm back for some more expert help. Here's what I am doing and what I tried. My database has entries with Contract Names and Expiry Dates, among other fields. I have a form designed to show the expiring contracts. To do this I use a straight forward query in my form's ON LOAD code strwhere = " BETWEEN #" & Now() & "# AND #" & DateAdd("m", 6, Now()) & "#" Set MyQueryDef = MyDatabase.CreateQueryDef("qryMattersQuery",...
3
2548
by: pbd22 | last post by:
Hi. I need some help with structuring my query strings. I have a form with a search bar and some links. Each link is a search type (such as "community"). The HREF for the link's anchor looks like the following: <a href="?searchtype=2">Community</a>
2
1957
by: lindabaldwin | last post by:
Hello everyone, I am fairly new to VBA. I have a worksheet in Excel, named "Data Sheet" from which I am trying to query data. This worksheet contains the following data: unit (column A), date (column B), time range (column C), day of the week (column D), event (column E), and occurrences (column F). I want to be able to identify records that meet user set criteria. I then want to add the number in column F to another number in a different...
0
7876
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8251
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8234
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6654
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5739
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5408
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3859
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2385
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1478
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.