I am trying to take multi-selections from a listbox on a form and put it into a query. In my Search I have found that
I needed to take the multi-selections and put in a hidden text box….One I am having trouble with right VBA code….
afterupdate listbox event……. but I wonder if it will work because I have put in the text box what I believe will make the
query work and when I run my run query button it gives me a null answer, when trying “2” Or “3” in the textbox
any suggestions or answers for what its takes to make this work.
![]() |
There are isolated problems with current patches, but they are well-known and documented on this site. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
listbox (Access 97)
Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » listbox (Access 97)
- This topic has 4 replies, 4 voices, and was last updated 22 years, 4 months ago.
AuthorTopicWSGreg
AskWoody LoungerJanuary 6, 2003 at 4:05 pm #381429Viewing 3 reply threadsAuthorReplies-
WSdcardno
AskWoody LoungerJanuary 6, 2003 at 5:34 pm #642726Rather than try to take information from listboxes and put it directly into a query (I imagine by editing the SQL code for a query or concatenating SQL clauses), I have had better luck in taking the results from a combobox and putting them in a temporary table, and then using that table in a query to limit the result set.
For instance, I have a button on a particular form to print a report listing all proposals that were submitted in response to different Requests For Proposals (RFPs) – the user must select the RFPs to be reported on from a multi-select combo box. The relevant code is shown below:
The report opened in the btnPrintProjectStatusReport routine is based on a query that includes the tblTempSelectedRFP table, so the result set only reflects records that match the values in that table, which have just been taken from the combobox on the form.
Private Sub btnPrintProjStatusReport_Click() Dim DocName As String Dim ExChoice As OptionGroup Dim ExFile As String Dim strFullName As String Dim strWordTemplate As String Dim strWordData As String Dim StrPath As String Dim iPathLen As Integer Dim objWordApp As Word.Application Set ExChoice = Me.optnExportTo ' provides choice of export to Word, Excel, or native Access Report ExFile = "qryProp+ContractforRFP&Rank" MakeCallTable See Below If DCount("*", "tblTempSelectedRFP") < 1 Then MsgBox "No Proposal Calls Selected for Reporting" Else Select Case ExChoice.Value Case 0 ' no export - generates Access report DocName = "rptStatusReport5" DoCmd.OpenReport DocName, acPreview DoCmd.Maximize RunCommand acCmdFitToWindow Case 1 ' Export to Word snip - bunch of code to open word, run mail merge, etc..... Case 2 ' export to Excel snip - "docmd" to export to Excel, etc.... End Select ExChoice.Value = 0 End If End Sub
This routine calls another sub to create a temporary table:
Private Sub MakeCallTable() ' creates 'tblTempSelectedRFP' which lists RFP Calls to be included in ' status report. The table survives until this routine is run again. Dim dbs As Database Dim qdfClean As QueryDef Dim qdfResetActive As QueryDef Dim rst As DAO.Recordset Dim ctllist As ListBox Dim ctlStatus As OptionGroup Dim Item As Variant Set dbs = CurrentDb Set qdfClean = dbs.QueryDefs("qryDeleteRFPSelectedRecords") Set qdfResetActive = dbs.QueryDefs("qryUpdateActiveField") Set ctllist = Me!lstbxRFPSelectList Set ctlStatus = Me!optnProjectStatus Set rst = dbs.OpenRecordset("tblTempSelectedRFP") qdfResetActive.Execute ' resets the manual "active" field to "No" to avoid double-counting qdfClean.Execute ' deletes all records from tblTempSelectedRFP DoCmd.SetWarnings False For Each Item In ctllist.ItemsSelected With rst .AddNew !RFPSequence = ctllist.ItemData(Item) !DispRank = ctlStatus.Value .Update End With Next Item DoCmd.SetWarnings True Set dbs = Nothing Set qdfClean = Nothing Set qdfResetActive = Nothing Set ctllist = Nothing Set ctlStatus = Nothing Set rst = Nothing End Sub
Hope that helps….
-
WSAndyAinscow
AskWoody LoungerJanuary 6, 2003 at 6:27 pm #642743You can loop through the selected items in the listbox with a VBA routine and build the filter string directly. Then modify the SQL directly or use this as a filter for a recordset – it depends on what you want to do. Make certain that you get the keys from the listbox not the displayed value if you have a hidden column for the key value.
-
WScharlotte
AskWoody Lounger -
WSGreg
AskWoody Lounger
Viewing 3 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
-
Windows 11 Insider Preview Build 26100.4202 (24H2) released to Release Preview
by
joep517
59 minutes ago -
Windows Update orchestration platform to update all software
by
Alex5723
5 hours, 31 minutes ago -
May preview updates
by
Susan Bradley
44 minutes ago -
Microsoft releases KB5061977 Windows 11 24H2, Server 2025 emergency out of band
by
Alex5723
7 hours, 17 minutes ago -
Just got this pop-up page while browsing
by
Alex5723
5 hours, 12 minutes ago -
KB5058379 / KB 5061768 Failures
by
crown
2 hours, 8 minutes ago -
Windows 10 23H2 Good to Update to ?
by
jkitc
20 minutes ago -
At last – installation of 24H2
by
Botswana12
21 hours, 3 minutes ago -
MS-DEFCON 4: As good as it gets
by
Susan Bradley
1 hour, 54 minutes ago -
RyTuneX optimize Windows 10/11 tool
by
Alex5723
1 day, 9 hours ago -
Can I just update from Win11 22H2 to 23H2?
by
Dave Easley
1 day, 2 hours ago -
Limited account permission error related to Windows Update
by
gtd12345
1 day, 22 hours ago -
Another test post
by
gtd12345
1 day, 22 hours ago -
Connect to someone else computer
by
wadeer
1 day, 17 hours ago -
Limit on User names?
by
CWBillow
1 day, 20 hours ago -
Choose the right apps for traveling
by
Peter Deegan
1 day, 10 hours ago -
BitLocker rears its head
by
Susan Bradley
18 hours, 16 minutes ago -
Who are you? (2025 edition)
by
Will Fastie
17 hours, 13 minutes ago -
AskWoody at the computer museum, round two
by
Will Fastie
1 day, 12 hours ago -
A smarter, simpler Firefox address bar
by
Alex5723
2 days, 9 hours ago -
Woody
by
Scott
2 days, 18 hours ago -
24H2 has suppressed my favoured spider
by
Davidhs
17 hours, 52 minutes ago -
GeForce RTX 5060 in certain motherboards could experience blank screens
by
Alex5723
3 days, 8 hours ago -
MS Office 365 Home on MAC
by
MickIver
3 days, 2 hours ago -
Google’s Veo3 video generator. Before you ask: yes, everything is AI here
by
Alex5723
3 days, 22 hours ago -
Flash Drive Eject Error for Still In Use
by
J9438
17 hours, 37 minutes ago -
Windows 11 Insider Preview build 27863 released to Canary
by
joep517
4 days, 17 hours ago -
Windows 11 Insider Preview build 26120.4161 (24H2) released to BETA
by
joep517
4 days, 17 hours ago -
AI model turns to blackmail when engineers try to take it offline
by
Cybertooth
3 days, 21 hours ago -
Migrate off MS365 to Apple Products
by
dmt_3904
3 days, 22 hours 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.