I am really stumped!! I am trying to pass values from a multi-select list box (ItemsSelected) to a query parameter. I want to used the bound column in the list box to populate a select query so the query can pull all the records associated with the selected list box values. I have had success in this when the list box is not a multi select box. I seems that the behavior is all together different when it is designated multi-select. Can anyone help? Thanks
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
multi-select list box (access 2K w/ windows 2K)
Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » multi-select list box (access 2K w/ windows 2K)
- This topic has 12 replies, 4 voices, and was last updated 20 years, 2 months ago.
AuthorTopicWSmcneilkm
AskWoody LoungerMarch 22, 2005 at 6:59 pm #417425Viewing 0 reply threadsAuthorReplies-
WSHansV
AskWoody LoungerMarch 22, 2005 at 7:49 pm #936522See for example post 438581 for how to handle a multiselect list box.
-
WSmcneilkm
AskWoody LoungerMarch 22, 2005 at 8:36 pm #936537Hans,
Thank you for the tip. I have applied what I thought was the relevent part of the code to my situation. I sent the sql to a text box on the form and if gives me the following :
“select Pricing_ID from Pricing where Pricing_ID in (N0684.019.1N2100,N0684.019.2N2100,N0684.019N2100))”
How do I get rid of the “select Pricing_ID from Pricing where Pricing_ID in”
and just leave the query parameter that I need which would be
” N0684.019.1N2100,N0684.019.2N2100,N0684.019N2100 ” ?
Or in my attempt to fit this code to my situation leave something off that I should not have?
The “fit my situation code” looks something like this:
“Dim frm As Form, ctl As Control
Dim varItem As Variant
Dim strSQL As String
Dim strWhere As String
Set frm = Forms!frmQuerySearchResults
Set ctl = frm!vQuery_ResultsFor Each varItem In Me.vQuery_Results.ItemsSelected
strWhere = strWhere & “,” & Me.vQuery_Results.ItemData(varItem)Next varItem
strWhere = Mid(strWhere, 2)
strSQL = “select Pricing_ID from Pricing where Pricing_ID in (” & strWhere & “))”
Me![Text8] = strSQL”
Thanks for your help.
-
WSHansV
AskWoody LoungerMarch 22, 2005 at 9:29 pm #936551If you want to use it as a query parameter, it should be
In (“N0684.019.1N2100″,”N0684.019.2N2100″,”N0684.019N2100”)
(quotes around the values since they are strings). To get this:
Dim frm As Form, ctl As Control
Dim varItem As Variant
Dim strWhere As StringSet frm = Forms!frmQuerySearchResults
Set ctl = frm!vQuery_ResultsFor Each varItem In Me.vQuery_Results.ItemsSelected
strWhere = strWhere & “,” & Chr(34) & Me.vQuery_Results.ItemData(varItem) & Chr(34)
Next varItemstrWhere = “In (” & Mid(strWhere, 2) & “)”
Me![Text8] = strWhere
-
WSmcneilkm
AskWoody LoungerMarch 23, 2005 at 1:14 pm #936719Hans,
thanks again for the help. I now have the correct (I Think) string being passed to the text box on the form. However, when I set the select query criteria to that text box it produces nothing. If i copy and paste the string directly from the text box into the query criteria and run the query it gives me the results I want. Can I not set the criteria for a select query to the string in the text box? The string that is produced and sent to the text box is the exact string that is built into the select query criteria when I build it manually. The query does not work from the text box but when input directly into the query it works. The code that I am using is below.Dim frm As Form
Dim varItem As Variant
Dim strSQL As String
Dim strWhere As String
Set frm = Forms!frmQuerySearchResults
Set ctl = frm!vQuery_ResultsFor Each varItem In Me.vQuery_Results.ItemsSelected
strWhere = strWhere & ” Or ” & Chr(34) & Me.vQuery_Results.ItemData(varItem) & Chr(34)Next varItem
strWhere = Mid(strWhere, 5)
strSQL = strWhere
Me![Text8] = strSQL
MsgBox strSQLAny thoughts?
Thanks -
WSHansV
AskWoody LoungerMarch 23, 2005 at 1:33 pm #936724It won’t work that way. Let’s take an example: you have a number field ID and you set the criteria in the query design grid to 1 Or 2 Or 3. The translation into SQL is WHERE ID=1 OR ID=2 OR ID=3.
What exactly do you mean by “Can I not set the criteria for a select query to the string in the text box?” How do you intend to use the string in the text box?
-
WSmcneilkm
AskWoody LoungerMarch 23, 2005 at 1:51 pm #936734Thanks for getting back to me so quickly. Here is the scenario for intended use. These are proposals for which I need to pull associated hours out of the database. I want the user to select the appropriate proposals from the list box. Then I want to run a query that takes all of the selected items from the text box and pull the associated hours from the database. Each proposal will have many records associated with it. Each record has a certain number of proposed hours. I want to display and report on all the reords associated with the selections in the list box. Does this help?
-
WSHansV
AskWoody LoungerMarch 23, 2005 at 2:05 pm #936741End users should never open queries directly. They should open a form or report based on the query instead. You can use a where-condition to filter the form or report.
Dim frm As Form, ctl As Control
Dim varItem As Variant
Dim strWhere As StringSet frm = Forms!frmQuerySearchResults
Set ctl = frm!vQuery_ResultsFor Each varItem In Me.vQuery_Results.ItemsSelected
strWhere = strWhere & “,” & Chr(34) & Me.vQuery_Results.ItemData(varItem) & Chr(34)
Next varItemstrWhere = “PricingID In (” & Mid(strWhere, 2) & “)”
‘ to open a form:
DoCmd.OpenForm FormName:=”frmMyForm”, WhereCondition:=strWhere
‘ or if you want to open a report:
DoCmd.OpenReport ReportName:=”rptMyReport”, View:=acViewPreview, WhereCondition:=strWhere -
WSmcneilkm
AskWoody LoungerMarch 23, 2005 at 2:42 pm #936755Hans,
All of this data is passed to me via a third party and resides in access tables. There is a move a foot here to standarize a report using this data but in excel format. I am investigating our ability to get the data from access to excel. I wanted to use the transfer spreedshett method. I wanted to use a query (Possibly a make table query) to extract the data save it in a table and pass it to excel. In my vision of how this was going to work I wanted to pass the query parameter to the text box. I had a button on the form that would launch the query using the parameter criteria in the text box. This then could pass to excel. Excel is important here because this data is going to be used by another program that can handle excel and not access. If there is no way to accomplish this by using a query, is there another way I can get a record set from selected items in a multi select list box and pass that record set to excel? I am already using automation in word in another database and think that once I can get the recordset I need should be able to use automation with excel also.Thanks
-
WSHansV
AskWoody LoungerMarch 23, 2005 at 3:01 pm #936766There is no way to pass a where-condition to a query the way you can do that for a form or report. You could set the complete SQL for a query using DAO. You need to set a reference to the Microsoft DAO 3.6 Object Library in Tools | References…
Dim dbs As DAO.Database
Dim qdf As DAO.QueryDef
Dim strSQL As String‘ assemble SQL string in code
strSQL = “SELECT … FROM … WHERE …”
Set dbs = CurrentDb
Set qdf = dbs.QueryDefs(“qryTest”)
qdf.SQL = strSQL‘ export query to Excel
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, “qryTest”, … -
WSmcneilkm
AskWoody LoungerMarch 24, 2005 at 6:08 pm #937016Hans,
Thank you for you help. As it turns out, I could was not comfortable using the multi select list box and the degree of programming it required. I came up with a work around that uses a regular list box and once an item is selected it copies the data to a new table for export. The user can select multiple items by selecting each one and clickin an add button. After all are seleced I just transfer the spreadsheet to excel. Thanks again for your help -
WSMarkD
AskWoody LoungerApril 15, 2005 at 4:48 pm #941234A belated reply, it looks like you resolved this issue, but if interested in example of how to use a multi-select listbox for query criteria, see attached demo database (A2K format). Open frm_Demo, select one or more items in list, then click Open Query button. A query will open, filtered by selected items. This uses technique described in ACC2000: How to Create a Parameter In() Statement, modified somewhat – instead of a parameter, the query (qry_CustomerOrders) has calculated field that calls a function (GetControlVal) that returns the value of specified control on an open form:
InParamEx([Customers]![CustomerID],GetControlVal(“frm_Demo”,”SelectedItems_txt”))
InParamEx is the function based on MSKB article. See code module basInParam and MSKB article for further details. Whenever user selects/unselects items in listbox, an “In” string is generated and stored in textbox (SelectedItems_txt). In actual use, the textbox (or footer) would be hidden from user, visible here for demo purposes.
I’ve used this technique with multiple multi-select listboxes to generate more complex query criteria for reports, export functions, etc, & worked OK. The attached demo is simplified version, using stripped-down versions of the Northwind Customers and Orders tables. You may be able to adapt this somewhat Rube Goldberg-like technique for your own project.
HTH
-
WSSupport4John
AskWoody Lounger
-
-
-
-
Viewing 0 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
How get Group Policy to allow specific Driver to download?
by
Tex265
9 minutes ago -
AI is good sometimes
by
Susan Bradley
1 hour, 18 minutes ago -
Mozilla quietly tests Perplexity AI as a New Firefox Search Option
by
Alex5723
2 hours, 20 minutes ago -
LibreOffice 25.8. No Windows 7, 8/8.1, x86
by
Alex5723
28 minutes ago -
Perplexity Pro free for 12 mos for Samsung Galaxy phones
by
Patricia Grace
21 hours, 19 minutes ago -
June KB5060842 update broke DHCP server service
by
Alex5723
19 hours, 51 minutes ago -
AMD Ryzen™ Chipset Driver Release Notes 7.06.02.123
by
Alex5723
23 hours, 53 minutes ago -
Excessive security alerts
by
WSSebastian42
50 minutes ago -
* CrystalDiskMark may shorten SSD/USB Memory life
by
Alex5723
1 day, 9 hours ago -
Ben’s excellent adventure with Linux
by
Ben Myers
49 minutes ago -
Seconds are back in Windows 10!
by
Susan Bradley
20 hours, 30 minutes ago -
WebBrowserPassView — Take inventory of your stored passwords
by
Deanna McElveen
3 hours, 3 minutes ago -
OS news from WWDC 2025
by
Will Fastie
26 minutes ago -
Need help with graphics…
by
WSBatBytes
4 hours, 40 minutes ago -
AMD : Out of Bounds (OOB) read vulnerability in TPM 2.0 CVE-2025-2884
by
Alex5723
2 days ago -
Totally remove or disable BitLocker
by
CWBillow
23 hours, 57 minutes ago -
Windows 10 gets 6 years of ESU?
by
n0ads
1 day, 3 hours ago -
Apple, Google stores still offer China-based VPNs, report says
by
Nibbled To Death By Ducks
2 days, 11 hours ago -
Search Forums only bring up my posts?
by
Deo
6 hours, 2 minutes ago -
Windows Spotlight broken on Enterprise and Pro for Workstations?
by
steeviebops
2 days, 23 hours ago -
Denmark wants to dump Microsoft for Linux + LibreOffice
by
Alex5723
2 days, 15 hours ago -
How to get Microsoft Defender to honor Group Policy Setting
by
Ralph
2 days, 23 hours ago -
Apple : Paragon’s iOS Mercenary Spyware Finds Journalists Target
by
Alex5723
3 days, 10 hours ago -
Music : The Rose Room – It’s Been A Long, Long Time album
by
Alex5723
3 days, 11 hours ago -
Disengage Bitlocker
by
CWBillow
3 days, 1 hour ago -
Mac Mini M2 Service Program for No Power Issue
by
Alex5723
3 days, 13 hours ago -
New Win 11 Pro Geekom Setup questions
by
Deo
6 hours, 6 minutes ago -
Windows 11 Insider Preview build 26200.5651 released to DEV
by
joep517
3 days, 20 hours ago -
Windows 11 Insider Preview build 26120.4441 (24H2) released to BETA
by
joep517
3 days, 20 hours ago -
iOS 26,, MacOS 26 : Create your own AI chatbot
by
Alex5723
4 days ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.