• Looping through queries (Access 97 SR 2)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Looping through queries (Access 97 SR 2)

    Author
    Topic
    #366892

    I have created a large group of queries that I would like ouput to Excel. I often need to add or delete. I’ve created a macro through the Macro tab to output them but I would like to use VBA instead. I would like to just loop through, running each query and sending the results to an Excel file with the file name that of the query. Any help would be greatly appreciated.

    Viewing 1 reply thread
    Author
    Replies
    • #570440

      Lookup “TransferSpreadsheet” in Help, and I think you will find what you need for correctly writing the code to export a query to Excel.

      • #570562

        Thanks for the reply. I had the code to export ,what I can’t figure out is how to loop through each query. Something like
        For each query in database
        docmd…

        • #570575

          Hi,
          You need to look at the querydefs collection. Something like:
          for each qdfTemp in currentdb.querydefs
          ….
          next qdfTemp
          Hope that helps.

    • #570471

      In the database window, Tab Macros, right-click on a macro. Click Save As/ Export. Check Save as Visual Basic Module and press OK. Check or uncheck Add error… and Include Macro Comments and click Convert. In the Module tab of the database windows you have now a module named Converted Macro – Name Of the Macro. This module will act the same as the macro. Start with this to learn VBA code

    Viewing 1 reply thread
    Reply To: Looping through queries (Access 97 SR 2)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: