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, but widespread attacks make patching prudent. Go ahead and patch, but watch out for potential problems. |
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
-
Microsoft is killing Authenticator
by
Alex5723
11 minutes ago -
Downloads folder location
by
CWBillow
6 hours, 27 minutes ago -
Remove a User from Login screen
by
CWBillow
8 hours, 59 minutes ago -
TikTok fined €530 million for sending European user data to China
by
Nibbled To Death By Ducks
10 hours, 8 minutes ago -
Microsoft Speech Recognition Service Error Code 1002
by
stanhutchings
16 hours, 12 minutes ago -
Is it a bug or is it expected?
by
Susan Bradley
2 hours, 13 minutes ago -
Image for Windows TBwinRE image not enough space on target location
by
bobolink
12 hours, 45 minutes ago -
Start menu jump lists for some apps might not work as expected on Windows 10
by
Susan Bradley
20 hours, 45 minutes ago -
Malicious Go Modules disk-wiping malware
by
Alex5723
10 hours, 22 minutes ago -
Multiple Partitions?
by
CWBillow
11 hours, 1 minute ago -
World Passkey Day 2025
by
Alex5723
1 day, 4 hours ago -
Add serial device in Windows 11
by
Theodore Dawson
1 day, 19 hours ago -
Windows 11 users reportedly losing data due forced BitLocker encryption
by
Alex5723
2 minutes ago -
Cached credentials is not a new bug
by
Susan Bradley
2 days ago -
Win11 24H4 Slow!
by
Bob Bible
2 days ago -
Microsoft hiking XBox prices starting today due to Trump’s tariffs
by
Alex5723
1 day, 21 hours ago -
Asus adds “movement sensor” to their Graphics cards
by
n0ads
2 days, 2 hours ago -
‘Minority Report’ coming to NYC
by
Alex5723
1 day, 22 hours ago -
Apple notifies new victims of spyware attacks across the world
by
Alex5723
2 days, 11 hours ago -
Tracking content block list GONE in Firefox 138
by
Bob99
2 days, 10 hours ago -
How do I migrate Password Managers
by
Rush2112
1 day, 18 hours ago -
Orb : how fast is my Internet connection
by
Alex5723
1 day, 20 hours ago -
Solid color background slows Windows 7 login
by
Alex5723
2 days, 22 hours ago -
Windows 11, version 24H2 might not download via Windows Server Updates Services
by
Alex5723
2 days, 21 hours ago -
Security fixes for Firefox
by
Susan Bradley
26 minutes ago -
Notice on termination of services of LG Mobile Phone Software Updates
by
Alex5723
3 days, 9 hours ago -
Update your Apple Devices Wormable Zero-Click Remote Code Execution in AirPlay..
by
Alex5723
3 days, 18 hours ago -
Amazon denies it had plans to be clear about consumer tariff costs
by
Alex5723
3 days, 9 hours ago -
Return of the brain dead FF sidebar
by
EricB
2 days, 20 hours ago -
Windows Settings Managed by your Organization
by
WSDavidO61
1 day, 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.