473,386 Members | 1,741 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.

list box as query criteria

Friends,

I have a form named Welcome on which there are various pages. On one
page, simply named PAGE1, I have added a list box named LSTINITIALS,
which stores the initials of my database users. This list box is also
used to supply criteria to a query named WELCOMELOOKUP.

On the same form I have added another list box named LSTSSN which has
the query named WELCOMELOOKUP as row source.

This query has 5 field, one of which is named INITIAL and has the
following criteria: FORMS!WELCOME!LSTINITIALS. The query source is a
table named CASES.

What I would like is that my LSTSSN would return all records according
to the selected record in the list box LSTINITIALS.

Can anyone give me a better solution?

Thanks.
Nov 13 '05 #1
5 16571
jp***@tin.it (Paolo) wrote in message news:<9f*************************@posting.google.c om>...
Friends,

I have a form named Welcome on which there are various pages. On one
page, simply named PAGE1, I have added a list box named LSTINITIALS,
which stores the initials of my database users. This list box is also
used to supply criteria to a query named WELCOMELOOKUP.

On the same form I have added another list box named LSTSSN which has
the query named WELCOMELOOKUP as row source.

This query has 5 field, one of which is named INITIAL and has the
following criteria: FORMS!WELCOME!LSTINITIALS. The query source is a
table named CASES.

What I would like is that my LSTSSN would return all records according
to the selected record in the list box LSTINITIALS.

Can anyone give me a better solution?

Thanks.


if you're only using a single record in your listbox, then use a
combobox instead, and create a subform with the related records. When
you run the combobox wizard, select "go to record..." and that should
do it.
Nov 13 '05 #2
RE/
This query has 5 field, one of which is named INITIAL and has the
following criteria: FORMS!WELCOME!LSTINITIALS. The query source is a
table named CASES


I've had trouble with getting queries to look into the contents of list and
combo boxes. If you approach doesn't work, try adding a AfterUpdate event to
the list that populates an invisible text field with what you want the query to
select on and aiming the query at that text field instead of the list box.
--
PeteCresswell
Nov 13 '05 #3
Paolo,
a few questions first... can the user select multiple options in the
listbox? If not, save yourself considerable headache and just use a
combobox. Otherwise, if you *really* want to use the listbox, there's
code here for what you want:

http://www.mvps.org/access/forms/frm0007.htm

you'd just set the rowsource and then requery the listbox...

the stuff on comboboxes might help too...

http://www.mvps.org/access/forms/frm0028.htm
Nov 13 '05 #4
pi********@hotmail.com (Pieter Linden) wrote in message news:<bf**************************@posting.google. com>...
Paolo,
a few questions first... can the user select multiple options in the
listbox? If not, save yourself considerable headache and just use a
combobox. Otherwise, if you *really* want to use the listbox, there's
code here for what you want:

http://www.mvps.org/access/forms/frm0007.htm


Dev's idea of creating SQL from a multiselect listbox is a good one:

'******************** Code Start ************************
Dim frm As Form, ctl As Control
Dim varItem As Variant
Dim strSQL As String
Set frm = Form!frmMyForm
Set ctl = frm!lbMultiSelectListbox
strSQL = "Select * from Employees where [EmpID]="
'Assuming long [EmpID] is the bound field in lb
'enumerate selected items and
'concatenate to strSQL
For Each varItem In ctl.ItemsSelected
strSQL = strSQL & ctl.ItemData(varItem) & " OR [EmpID]="
Next varItem

'Trim the end of strSQL
strSQL=left$(strSQL,len(strSQL)-12))
'******************** Code end ************************

Instead of using the code above, I would use something like:

'******************** Code Start ************************
Dim frm As Form, ctl As Control
Dim varItem As Variant
Dim strSQL As String
Dim intI As Integer

Set frm = Form!frmMyForm
Set ctl = frm!lbMultiSelectListbox
strSQL = "Select * from Employees"
'Assuming long [EmpID] is the bound field in lb
'enumerate selected items and
'concatenate to strSQL
intI = 0
For Each varItem In ctl.ItemsSelected
intI = intI + 1
If intI = 1 Then
strSQL = strSQL & " WHERE [EmpID] = " & ctl.ItemData(varItem)
Else
strSQL = strSQL & " OR [EmpID]= " & ctl.ItemData(varItem)
End If
Next varItem
'******************** Code end ************************

so that the case where no items are selected creates a valid SQL
string. In a more generalized version that includes other criteria
just tack on the " OR ... " parts for each selected item in the
listbox onto the WHERE part.

James A. Fortune
Nov 13 '05 #5
ja******@oakland.edu (James Fortune) wrote in message news:<a6*************************@posting.google.c om>...
pi********@hotmail.com (Pieter Linden) wrote in message news:<bf**************************@posting.google. com>...
Paolo,
a few questions first... can the user select multiple options in the
listbox? If not, save yourself considerable headache and just use a
combobox. Otherwise, if you *really* want to use the listbox, there's
code here for what you want:

http://www.mvps.org/access/forms/frm0007.htm


Dev's idea of creating SQL from a multiselect listbox is a good one:

'******************** Code Start ************************
Dim frm As Form, ctl As Control
Dim varItem As Variant
Dim strSQL As String
Set frm = Form!frmMyForm
Set ctl = frm!lbMultiSelectListbox
strSQL = "Select * from Employees where [EmpID]="
'Assuming long [EmpID] is the bound field in lb
'enumerate selected items and
'concatenate to strSQL
For Each varItem In ctl.ItemsSelected
strSQL = strSQL & ctl.ItemData(varItem) & " OR [EmpID]="
Next varItem

'Trim the end of strSQL
strSQL=left$(strSQL,len(strSQL)-12))
'******************** Code end ************************

Instead of using the code above, I would use something like:

'******************** Code Start ************************
Dim frm As Form, ctl As Control
Dim varItem As Variant
Dim strSQL As String
Dim intI As Integer

Set frm = Form!frmMyForm
Set ctl = frm!lbMultiSelectListbox
strSQL = "Select * from Employees"
'Assuming long [EmpID] is the bound field in lb
'enumerate selected items and
'concatenate to strSQL
intI = 0
For Each varItem In ctl.ItemsSelected
intI = intI + 1
If intI = 1 Then
strSQL = strSQL & " WHERE [EmpID] = " & ctl.ItemData(varItem)
Else
strSQL = strSQL & " OR [EmpID]= " & ctl.ItemData(varItem)
End If
Next varItem
'******************** Code end ************************

so that the case where no items are selected creates a valid SQL
string. In a more generalized version that includes other criteria
just tack on the " OR ... " parts for each selected item in the
listbox onto the WHERE part.

James A. Fortune

Cool! I like the alternative way to figuring out the OR stuff... I
always found that a pain when executing the SQL... it would always
flake out because I trimmed too much.
Nov 13 '05 #6

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

Similar topics

7
by: keliie | last post by:
Hello Just a quick question that I've spent a few hours trying to solve with no luck (although one would think this should be fairly easy). I have a form with a subform. The subform is based...
3
by: stevecat | last post by:
Hi there, I have created a form, "search" and a query "search_product". The query returns the product information based upon the criteria for three of the fields, author, title or isbn. The field...
4
waynetheengineer
by: waynetheengineer | last post by:
Hi, I was wondering if anyone had any suggestions on my database: I have a form that accepts user input into a single text box. When the OK button is hit, a query should search for all records...
3
by: ericargent | last post by:
Hi I'm using Acces 2003 I have Query where the several parameters for the criteria are supplied from a form. One parameter source is a combo box. What I am trying to do is if: An item is...
6
craigfr
by: craigfr | last post by:
I am making a graph comparing last year's defect data with YTD defect data. Our fiscal year starts Nov.1 and ends Oct.31. To get the YTD, I started used a simple date serial criteria: Between...
3
by: sfrvn | last post by:
I have searched high and low and cannot find an answer to my problem. So now I turn to the collective genius of this newsgroup. Over-simplified examples This query criteria for field works:...
2
by: cmartin1986 | last post by:
First of all I want to thank all of you that have helped me in the past this is an awesome fourm. My problem today is I have a database that builds charts that are viewed by a large group every...
4
by: tbeers | last post by:
Is there a method to pass along a criteria argument directly to the query criteria rather than through filtering a form or report? In other words, I would like to click a "print" button and in the...
8
by: limperger | last post by:
Hello everyone! First and foremost, my apologies for the title of the post. It is not very clarifying of what the problem is about, but I didn't know how to put it... My problem is as follows: I...
9
ajhayes
by: ajhayes | last post by:
Hello everyone, This is my first time posting here and I'm hoping someone can help me out. I'm a relative newbie to Access and am pretty much learning as I go along, so please bear with me. ...
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: 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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.