List Box to run multiple queries

Posted on 2004-11-18
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
    LVL 58

    Accepted Solution

    Private Sub cmdRun_Click()

        Dim varItem

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

    End Sub

    Author Comment

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

    Author Comment

    it was just a typo on itemdata().

         Docmd.OpenQuery lstAvailQry.ItemData(varItem)

     I corrected it -- thank you so much.
    LVL 4

    Expert Comment

    In case that doesn't work:

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

    Expert Comment

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

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    The first two articles in this short series — Using a Criteria Form to Filter Records ( and Building a Custom Filter ( — discuss in some detail how a form can be…
    Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
    Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    730 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

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now