+ Reply to Thread
Results 1 to 8 of 8

Run Access query using SQL in VBA

Hybrid View

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

    Run Access query using SQL in VBA

    Hello,

    I have an Access query that I am trying to run and then have the output of that data go to an excel spreadhseet. I know there are ways to do it with importing the entirety of the output, but I would like specifics within that query, therefore I need to use SQL code. Does anyone know how to import Access using the SQL data into excel using a VBA code?


    Thank you!!

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

    Re: Run Access query using SQL in VBA

    Quick additional info:

    Let's call the code I have SQLCode1
    The location in excel I want to paste it: Cell A5 in Sheet "DataHub"
    The location: "C:\Generic\Generic.mdb"
    And the query name called QueryA

    Thanks!

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Run Access query using SQL in VBA

    What do you mean by the 'specifics' of the query?
    If posting code please use code tags, see here.

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

    Re: Run Access query using SQL in VBA

    Like for example, the query in itself is too large for excel, to just import the entire query results. So I am trying to import based on the state I am working with. I.e. I want to import QueryA, which gives me info on state specific items, for each state and I want it to just bring back the results for TX.

    I hope that makes sense.

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Run Access query using SQL in VBA

    Have you set up the query to take parameters, eg state, for criteria?

    Also, what are you going to do with the data once you have it in Excel?

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

    Re: Run Access query using SQL in VBA

    Yeah, the query has a where for the state. The problem is that it is going to be variable. So once I am able to find code that works, I was going to make it point to a variable cell that already has the desired state selected.

    This button is for a mass use by analysts on my team. Once I get the data, I am pasting it in a specific section on a template that then does a lot of other things (that I already have completed) based on that data.

    So my final step is getting this data imported from Access pulling in just the State information I want from Access.

    I hope that wasn't confusing, but outside of giving company specifics, that's the best way to describe it using the generalities I'm required to.

    Thank you so much for taking interest and trying to help.

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Run Access query using SQL in VBA

    You could do this with a Data Query including using a cell to specify the state criteria.

    If that's not the route you want to take then you'll need to look at using ADO.

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

    Re: Run Access query using SQL in VBA

    Alright, thanks. I will have a look around Google and try and find something that works for me using one of those.

    Thanks for the interest in my issue.

+ 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. Importing Access query into Excel:Microsoft Query
    By ge0rge in forum Excel General
    Replies: 3
    Last Post: 04-02-2009, 10:51 AM
  2. Can I use MS Query in Excel like an Append Query in Access
    By Sam Wardill in forum Excel General
    Replies: 0
    Last Post: 04-11-2006, 09:45 AM
  3. Replies: 0
    Last Post: 03-19-2006, 08:50 PM
  4. Database Query-a query that reads data from MS Access
    By Osmar Mateus in forum Excel General
    Replies: 4
    Last Post: 01-29-2006, 04:10 PM
  5. [SOLVED] Run Access query from Excel, input value to query being value in c
    By Nagesh in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-22-2005, 10:10 AM

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