Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Multi Select Boxes as Query Parameters
Seth M 
   
11 years ago
Howdy!  

It seems this question has been posed all over the interwebs, but my problem has me stuck.  I'd appreciate any help!

I need to be able to run a query based on the selections from a MULTI-Select listbox.  Documentation is very clear that you cannot simply reference the listbox in your query, as the multiselect option will simply return a null value.

The solutions I have found seem to be to create a string based on the list items with a code like this:

Dim frm As Form, ctl As Control
Dim varItem As Variant
Dim strSQL As String
    Set frm = Form!frmMyForm
    Set ctl = frm!lbMultiSelectListbox
    strSQL = "Select * from Employees where [EmpID]="
    'Assuming long [EmpID] is the bound field in lb
    'enumerate selected items and
    'concatenate to strSQL
    For Each varItem In ctl.ItemsSelected
        strSQL = strSQL & ctl.ItemData(varItem) & " OR [EmpID]="
    Next varItem

    'Trim the end of strSQL
    strSQL=left$(strSQL,len(strSQL)-12))


However, what do I do if my listbox information is populated by an additional query in the form (based on the year), and is therefore variable?  

Here's some background info:  The database I operate tracks the fundraising for hundreds of team members across dozens of teams.  Each year, new teams and teammembers are formed.

I already have set up a form that allows me to email individual team members their balance report (Thanks to Richard and his Email via SMTP tutorial), but now I need to set up bulk mailing.

The workflow looks like this:  I want to be able to select multiple teams from the multi-select listbox, hit "send", and have the database query that pulls all of the team members based on the teams selected, generates individual reports for those individual team members, then works through the email form one record at a time.

My biggest hurdle is the query based on multiple selections from a listbox.  The second hurdle will be setting up the email loop, but I'm confident that Richard's course on that will suffice.

Thanks to anyone who can point me in the right direction!

Seth
[email protected]



Reply from Alex Hedley:

I'd say the way the listbox is filled is irrelevant.
Once you have the data in it you can use it how you want.

If you have a single email working just make that a function with a parameter, To address (and any others that are going to change per person).
Now you can add a loop

For Each varItem In ctl.ItemsSelected
  SENDEMAIL(varItem)
Next varItem

varItem being the email address.

If you have a single report working it's just a case of wrapping that whole procedure and looping that.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/15/2026 11:37:46 AM. PLT: 1s