+ Reply to Thread
Results 1 to 5 of 5

VBA to export Access Query results to Excel

  1. #1
    Registered User
    Join Date
    04-10-2013
    Location
    Los Angeles
    MS-Off Ver
    Excel 2010
    Posts
    32

    VBA to export Access Query results to Excel

    Hi again,

    Feel like I've asked a million questions recently, but here's another......

    This code works perfectly fine to run an access query, and then paste the results in a sheet in my open excel document. No issue there.....

    However, is there any way I can modify this to add a variable so that I can select only certain data? For example, adding in a "WHERE STATE_CODE = 'TX' " or something like that?


    Please Login or Register  to view this content.
    Thanks!

  2. #2
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: VBA to export Access Query results to Excel

    Add a parameter to the Access query (edit it in Access) and then populate that with the contents of a variable in the Excel code.

    Would give more specific details but using a phone at the moment. Maybe it'll give you a start, at least.

  3. #3
    Registered User
    Join Date
    04-10-2013
    Location
    Los Angeles
    MS-Off Ver
    Excel 2010
    Posts
    32

    Re: VBA to export Access Query results to Excel

    Thank you for your response. I appreciate it.

    The thing is, I'm trying to have it all done in Excel. This is going to be a widely used template for a bunch of analysts and so it would cause possible issues with several people editing the same access query but needing different filters.

    I had originally planned on just importing all of the the query results and then filtering them from the sheet on excel, but the issue with that is the results are larger than what excel can handle, so I need to just import the section that is of focus. In this case, I mean just import the state that is being analyzed.

    Thanks!

  4. #4
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: VBA to export Access Query results to Excel

    OK - try creating the query in VBA (Use the Access query to get the basic SQL string)

    Please Login or Register  to view this content.
    Again, rough and ready - the phone does have some limitations.

  5. #5
    Registered User
    Join Date
    04-10-2013
    Location
    Los Angeles
    MS-Off Ver
    Excel 2010
    Posts
    32

    Re: VBA to export Access Query results to Excel

    cytop, thanks for your help. Amazing what can be done on your phone. Pretty impressive.

    Anyway, I figured out what the problem was. The code you have up there basically is exactly what I ended up writing in there. However, the issue was that I was trying to run the query and something was getting confused. So all I had to do was turn that query into a table-making query and have it read off of the table it makes instead.

    Made life much easier.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Can I import the results of an Access Query into Excel?
    By MrChips in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-20-2012, 05:57 PM
  2. Copy or Export an Access Query results back to Excel
    By MACRE0 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-18-2008, 01:07 PM
  3. Pull query results from Access to Excel
    By yellephant in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 05-30-2007, 02:50 PM
  4. [SOLVED] VBA - query an Access table -> results in Excel
    By rirus in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-21-2006, 02:35 PM
  5. Access query results to Excel
    By piano banger in forum Excel General
    Replies: 2
    Last Post: 08-14-2006, 07:30 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1