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.
![]() |
Patch reliability is unclear, but widespread attacks make patching prudent. Go ahead and patch, but watch out for potential problems. |
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
-
Fedora Linux is now an official WSL distro
by
Alex5723
2 hours, 28 minutes ago -
May 2025 Office non-Security updates
by
PKCano
2 hours, 55 minutes ago -
Windows 10 filehistory including onedrive folder
by
Steve Bondy
4 hours, 50 minutes ago -
pages print on restart (Win 11 23H2)
by
cyraxote
4 hours, 6 minutes ago -
Windows 11 Insider Preview build 26200.5581 released to DEV
by
joep517
7 hours, 2 minutes ago -
Windows 11 Insider Preview build 26120.3950 (24H2) released to BETA
by
joep517
7 hours, 3 minutes ago -
Proton to drop prices after ruling against “Apple tax”
by
Cybertooth
14 hours, 24 minutes ago -
24H2 Installer – don’t see Option for non destructive install
by
JP
4 hours, 7 minutes ago -
Asking Again here (New User and Fast change only backups)
by
thymej
1 day, 1 hour ago -
How much I spent on the Mac mini
by
Will Fastie
1 hour, 10 minutes ago -
How to get rid of Copilot in Microsoft 365
by
Lance Whitney
2 hours, 56 minutes ago -
Spring cleanup — 2025
by
Deanna McElveen
1 day, 7 hours ago -
Setting up Windows 11
by
Susan Bradley
2 hours, 41 minutes ago -
VLC Introduces Cutting-Edge AI Subtitling and Translation Capabilities
by
Alex5723
1 day, 3 hours ago -
Powershell version?
by
CWBillow
1 day, 3 hours ago -
SendTom Toys
by
CWBillow
31 minutes ago -
Add shortcut to taskbar?
by
CWBillow
1 day, 7 hours ago -
Sycophancy in GPT-4o: What happened
by
Alex5723
2 days ago -
How can I install Skype on Windows 7?
by
Help
1 day, 22 hours ago -
Logitech MK850 Keyboard issues
by
Rush2112
1 day, 5 hours ago -
We live in a simulation
by
Alex5723
2 days, 14 hours ago -
Netplwiz not working
by
RetiredGeek
2 days ago -
Windows 11 24H2 is broadly available
by
Alex5723
3 days, 2 hours ago -
Microsoft is killing Authenticator
by
Alex5723
4 hours, 40 minutes ago -
Downloads folder location
by
CWBillow
3 days, 9 hours ago -
Remove a User from Login screen
by
CWBillow
2 days, 4 hours ago -
TikTok fined €530 million for sending European user data to China
by
Nibbled To Death By Ducks
3 days ago -
Microsoft Speech Recognition Service Error Code 1002
by
stanhutchings
3 days ago -
Is it a bug or is it expected?
by
Susan Bradley
1 day, 2 hours ago -
Image for Windows TBwinRE image not enough space on target location
by
bobolink
2 days, 23 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.