Results 1 to 6 of 6
  1. #1
    wptaylor4 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2013
    Posts
    9

    Using VBA to run multiple queries

    Hey folks, new to the forum so bear with me.



    I am using VBA to run multiple queries in access. So far I have the docmd.openquery "various queries" thing set up fine, but naturally there is a catch.

    The queries I am setting up are append queries to take a big file and disperse it over multiple (13) tables. This requires me typing in a 4 digit YYMM to append them and it happens for each query. Therefore even though I am running them all in a row I still need to type in "1306" 13 times to key the june 2013 entries. I was wondering if there was anyway for vba to automatically key this or if there is anyway for me to adjust my vba or queries so that I only have to key it one time. I have included my code for what I have now.

    Public Sub QueryRunner()


    DoCmd.OpenQuery ("Query1")
    DoCmd.OpenQuery ("Query2")
    DoCmd.OpenQuery ("Query3")
    ' and onward to query 13


    End Sub

    Any help would be greatly appreciated! Thanks!

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    I would run the sub from a form where you enter the criteria in a textbox, and have all the queries get the value from there.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    wptaylor4 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2013
    Posts
    9
    Thanks for the quick response. Unfortunately I am relatively new to access and have little idea on how to do that. Could you clarify?

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    The criteria would look like

    Forms!FormName.TextboxName

    instead of

    [Enter year]
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    wptaylor4 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2013
    Posts
    9
    Thanks so much. This is as good as solved for me

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Multiple FIRST/LAST Queries
    By dr4ke in forum Queries
    Replies: 2
    Last Post: 07-07-2012, 09:07 AM
  2. Replies: 1
    Last Post: 01-10-2012, 10:12 PM
  3. Multiple Queries and Reports
    By Chad E in forum Access
    Replies: 4
    Last Post: 10-18-2011, 01:47 PM
  4. SQL Multiple Queries
    By mbake085 in forum Queries
    Replies: 5
    Last Post: 05-13-2011, 01:03 PM
  5. Multiple database queries
    By G0zzy in forum Access
    Replies: 4
    Last Post: 08-28-2009, 12:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums