List Box to run multiple queries

Posted on 2004-11-18
Medium Priority
Last Modified: 2010-05-18
My question is a bit confusing, but I will try to explain. I have a list box (called "LstAvailQry" and muli-select is enabled to SIMPLE). The list displays several rows of data showing my available queries.  For example:
Query      Description
Query1    Show all employees Name and Address
Query2   [Show number of referrals by shift]
Query3    Show number of declined referrals by shift
Query4   [Show list of referrals closed by employee]

I want the user to be able to select multiple rows of data and click on a run button. The run button will then run all queries selected.  For example, if I select Queries 2 & 4, the application will run these two queries for me to view.

As I saw some samples in previous question and I believe they use the loop function, but I am not sure how to do that in my case.

Could you kindly provide some code that will run these queries?

Question by:epicazo
  • 2
  • 2
LVL 58

Accepted Solution

harfang earned 1000 total points
ID: 12615630
Private Sub cmdRun_Click()

    Dim varItem

    For Each varItem In lstAvailQry.ItemsSelected
        Docmd.OpenQuery lstAvailQry.ItemDate(varItem)
    Next varItem

End Sub

Author Comment

ID: 12615707
I get an error, method or data member not found... lstAvailQry.ItemDate(varItem)

Author Comment

ID: 12615725
it was just a typo on itemdata().

     Docmd.OpenQuery lstAvailQry.ItemData(varItem)

 I corrected it -- thank you so much.

Expert Comment

ID: 12615764
In case that doesn't work:

For Each qry In Me.LstAvailQry.ItemsSelected
DoCmd.OpenQuery qry
LVL 58

Expert Comment

ID: 12615844
My fingers often confuse "date" and "data"... good job!

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question