List box
My form allows the user to select items from a list box and then preview the report. The first time I ran it the report ran for a single list box selection. Now when I run it (for whatever selection I make, irregardless) the form continually comes up blank, even after closing it and restarting the form. My first time with a listbox. Please advise.
![]() |
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 |
-
List box (97)
Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » List box (97)
- This topic has 10 replies, 4 voices, and was last updated 23 years, 1 month ago.
AuthorTopicWSarage
AskWoody LoungerMarch 22, 2002 at 7:22 pm #368607Viewing 1 reply threadAuthorReplies-
WSR. Hicks
AskWoody LoungerMarch 22, 2002 at 8:03 pm #578073If you use a listbox to “multi-select” criteria for your report, you can not simply reference the list box from the query to retrieve the criteria.
You have to use code to “Loop” through the selections to dynamically create the “Where” argument to be used with the DoCmd.OpenReport method.
First set your lstbox to multi select property to Simple or Extended (depending on what you want, I use Simple most of the time). Leave the Control Source property for this lstbox empty (unbound).
Now to get the multi select values
-
WSaetaylor
AskWoody LoungerMarch 25, 2002 at 4:06 pm #578440I’ve tried to follow the procedure you set out for arage last week for my own project. I have a multiselect list box based on a table Committees. I have a report based on a very complicated query with lots of IIF statements and relying on two underlying queries. The query also prompts the user for a variable. Perhaps not surprising, my adaptation of your code (using elements from Helen Feddema) didn’t seem to work right. Would you mind helping me with this? Code below.
Private Sub Command6_Click()
On Error GoTo Err_Command6_ClickDim lst As Access.ListBox
Dim strWhere As String
Dim varItem As Variant
Dim lngID As LongSet lst = Me![fldSelectCommittee]
If lst.ItemsSelected.Count = 0 Then
MsgBox “Please select at least one committee”
lst.SetFocus
Exit Sub
End IflngID = lst.Column(0, varItem)
For Each varItem In lst.ItemsSelected
strWhere = strWhere & “CommitteeID =” _
& Chr(39) & lngID & Chr(39) & ” Or ”
Next varItemstrWhere = Left(strWhere, Len(strWhere) – 4)
DoCmd.OpenReport “MeetingCalendar”, acPreview, , strWhere
Exit_Command6_Click:
Exit SubErr_Command6_Click:
MsgBox Err.Description
Resume Exit_Command6_ClickEnd Sub
Also – here’s the rather inelegant SQL for the primary underlying query.
SELECT Meetings.CommitteeID, Committees.Committee, IIf([Meetings]![CommitteeID]=0,[Purpose],[Committee]) AS [Group], IIf(IsNull([SubGroup]),[Group],[Group] & ” – ” & [SubGroup]) AS MtgGroup, IIf([EventType]=”Meeting”,””,[EventType]) AS Type2, IIf([Type2]=”Subgroup Meeting”,””,[Type2]) AS Type1, IIf([Type1]=””,[MtgGroup],[MtgGroup] & ” – ” & [EventType]) AS Type, IIf([EventType]=”Report”,[ReportTitle],[Type]) AS Title, aryDate.StartMonth, Meetings.Year, aryDate.Days, IIf([TentativeDates]=Yes,”Tentative”,””) AS Tentative, Meetings.Time, Meetings.StartMonthID, Meetings.StartDay, aryDate.StartMonth
FROM (Committees RIGHT JOIN Meetings ON Committees.CommitteeID = Meetings.CommitteeID) LEFT JOIN aryDate ON Meetings.MeetingID = aryDate.MeetingID
WHERE (((Meetings.StartMonthID)>=[Enter Current Month – by number]))
ORDER BY Meetings.StartMonthID;Current Error: After it offers the user prompt, I get the error: Expression is typed incorrectly, or is too complex to be evaluated.
Thanks for any help you can provide.
Alysha Taylor
-
WSMarkLiquorman
AskWoody Lounger-
WSarage
AskWoody Lounger -
WSMarkLiquorman
AskWoody Lounger -
WSarage
AskWoody LoungerMarch 25, 2002 at 6:13 pm #578456I did run the debug at that point you mentioned & it looked fine like this in the debug window using debug.print:
Select * from tblFinancialAudit where [ReferenceNumber]=1401-63 OR [ReferenceNumber]=1401-64
And yes, when I substitute the value in strSql into the sql view of the query, it will run correctly.
-
WSMarkLiquorman
AskWoody LoungerMarch 25, 2002 at 8:30 pm #578473I’m surprised it will run in SQL view. The problem is that your ReferenceNumbers aren’t really numbers, they are strings. Modifiy your original code to bracket your entries with quotes, like this:
You had: strSQL = strSQL & ctl.ItemData(varItem) & " OR [ReferenceNumber]=" Change to: strSQL = strSQL & chr(34) & ctl.ItemData(varItem) & chr(34) & " OR [ReferenceNumber]="
-
WSarage
AskWoody Lounger -
WSMarkLiquorman
AskWoody LoungerMarch 26, 2002 at 2:20 am #578513You can use single or double quotes in the SQL statement to delineate strings.
Looking back on your code, I don’t know what you are using that strSQL string for anyway! I’d remove any competing WHERE clause from the query behind the report. Then instead of strSQL I’d form strWHERE, which is the WHERE clause part of strSQL (but without the word WHERE). Then use it in the OpenReport method.
-
WSarage
AskWoody Lounger
-
-
-
Viewing 1 reply thread -

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
-
Privacy and the Real ID
by
Susan Bradley
7 hours, 35 minutes ago -
MS-DEFCON 2: Deferring that upgrade
by
Susan Bradley
7 hours, 51 minutes ago -
Cant log on to oldergeeks.Com
by
WSJonharnew
9 hours, 40 minutes ago -
Upgrading from Win 10
by
WSjcgc50
2 hours, 59 minutes ago -
USB webcam / microphone missing after KB5050009 update
by
WSlloydkuhnle
1 hour, 44 minutes ago -
TeleMessage, a modified Signal clone used by US government has been hacked
by
Alex5723
22 hours, 18 minutes ago -
The story of Windows Longhorn
by
Cybertooth
10 hours, 3 minutes ago -
Red x next to folder on OneDrive iPadOS
by
dmt_3904
1 day ago -
Are manuals extinct?
by
Susan Bradley
4 hours, 17 minutes ago -
Canonical ditching Sudo for Rust Sudo -rs starting with Ubuntu
by
Alex5723
1 day, 9 hours ago -
Network Issue
by
Casey H
20 hours, 29 minutes ago -
Fedora Linux is now an official WSL distro
by
Alex5723
1 day, 21 hours ago -
May 2025 Office non-Security updates
by
PKCano
1 day, 21 hours ago -
Windows 10 filehistory including onedrive folder
by
Steve Bondy
1 day, 23 hours ago -
pages print on restart (Win 11 23H2)
by
cyraxote
1 day ago -
Windows 11 Insider Preview build 26200.5581 released to DEV
by
joep517
2 days, 1 hour ago -
Windows 11 Insider Preview build 26120.3950 (24H2) released to BETA
by
joep517
2 days, 1 hour ago -
Proton to drop prices after ruling against “Apple tax”
by
Cybertooth
2 days, 9 hours ago -
24H2 Installer – don’t see Option for non destructive install
by
JP
1 day, 1 hour ago -
Asking Again here (New User and Fast change only backups)
by
thymej
2 days, 20 hours ago -
How much I spent on the Mac mini
by
Will Fastie
4 hours, 6 minutes ago -
How to get rid of Copilot in Microsoft 365
by
Lance Whitney
23 hours, 44 minutes ago -
Spring cleanup — 2025
by
Deanna McElveen
3 days, 2 hours ago -
Setting up Windows 11
by
Susan Bradley
1 day, 21 hours ago -
VLC Introduces Cutting-Edge AI Subtitling and Translation Capabilities
by
Alex5723
2 days, 22 hours ago -
Powershell version?
by
CWBillow
2 days, 22 hours ago -
SendTom Toys
by
CWBillow
1 day, 9 hours ago -
Add shortcut to taskbar?
by
CWBillow
3 days, 2 hours ago -
Sycophancy in GPT-4o: What happened
by
Alex5723
3 days, 19 hours ago -
How can I install Skype on Windows 7?
by
Help
3 days, 17 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.