+ Reply to Thread
Results 1 to 19 of 19

Import Access Query To Excel

  1. #1
    Registered User
    Join Date
    10-25-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    13

    Import Access Query To Excel

    If someone could point me in the right direction I would really appreciate it. I am a very inexperienced Access and VBA user, and I am trying to import Access queries to an excel spreadsheet on a weekly basis. I have searched the web and there area a lot of examples out there that I have modified and tried myself, but with no luck. I am crrently using Access and Excel 2010. One of the issues I am running into is an "Unrecognized database format" as the database that I am currently pulling from has an .accdb format. I have run into a couple other error messages with other codes that I have modified for my use. I have to fill out this spreadsheet weekly and every bit of information is written in separate Access queries. The idea is to eventually have the queries autofill into their designated places in the spreadsheet. I have included the code that I currently have. Your help is greatly appreciated. Thanks





    Please Login or Register  to view this content.
    Last edited by alansidman; 10-25-2013 at 05:39 PM. Reason: code tags added

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2507 Win 11
    Posts
    24,918

    Re: Import Access Query To Excel

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (I have added them for you this time. Please read our rules and adhere to them in the future. )
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2507 Win 11
    Posts
    24,918

    Re: Import Access Query To Excel

    There are built in features of both Excel and Access that could be used to make this a very simple process.

    You could export the query directly from Access to Excel. With your query highlighted in the Navigation Pane, click on External, Export, Excel and then follow the wizard to export the query directly to Excel.

    Alternatively, you could do this reverse, in Excel, click on Data, Access, and follow the wizard to import the query to Excel.

    Is there any reason that you need a VBA solution to make this happen?

  4. #4
    Registered User
    Join Date
    10-25-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Import Access Query To Excel

    The idea behind writing a VBA solution was that I need to compile the data for this spreadsheet on a weekly basis. The data needs to be entered into specific cells on a spreadsheet, which seems like a fairly stright forward operation once the basic code is written. I assumed that a VBA would take a lot of the legwork out of having to run the query and then copy and paste the results which is what I am currently doing (there are a lot of queries that get the data for the spreadsheet). That being said I do not need a VBA to make this happen if there is a better way.

    I had stumbled upon the way import the query to Excel, however when I attempt to do this only a couple of the queries show up as "importable". I assume this is because most of the queries have an input date function that allows me to enter specific date ranges for the query to run.

    I did not know about the export query option in Access. I can run my query in the date ranges that I want but the problem is the data then becomes its own spreadsheet. I am then back to where I started and having to run each query seperately and then copying the data over to the actual spreadsheet I need to use.

  5. #5
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2507 Win 11
    Posts
    24,918

    Re: Import Access Query To Excel

    Look at this blog entry on how to export a query to a specific range in Excel using VBA.

    http://accessblog.net/2006/07/export...cel-range.html

    If you have issues with this, post back and will try to help you through the issues.

  6. #6
    Registered User
    Join Date
    10-25-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Import Access Query To Excel

    Thank you alasidman for your help, but still no luck in what I want to do. I have done a lot of searching of different forums with still no luck. The closest thing I have found to what I want to do is here. I have modified it to set it to my database and query in Access, with still no luck. I am recieving an error message " Run-Time error 3044. Application defined or object defined error" at the line Set MyQueryDef = MyDatabase.QueryDefs("Query Name"). I need the code to run the query and return the data in a date range. I want the user to input the date range that they want to return the data and then input the data into an already assembled spreadsheet. I believe that this code does that however I have no idea what the error message is telling me.

    Please Login or Register  to view this content.
    Thanks again for the help.

  7. #7
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2507 Win 11
    Posts
    24,918

    Re: Import Access Query To Excel

    I am not sure if this is the error or not. In that particular line that Access is throwing off the error, you have a typo.

    Please Login or Register  to view this content.
    Should be

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    10-25-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Import Access Query To Excel

    I wish...that was just an example of my proof reading skills. "Query Name" is just a place holder for the actual name of my query.

  9. #9
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2507 Win 11
    Posts
    24,918

    Re: Import Access Query To Excel

    I don't usually work with DAO and Recordsets or QueryDefs for moving data, but I found this link. I could be wrong, but I think you need a "CreateQueryDef" line in there.

    See if this link helps you.

    http://msdn.microsoft.com/en-us/libr.../ff194892.aspx

  10. #10
    Registered User
    Join Date
    10-25-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Import Access Query To Excel

    Thanks for the link. After looking at the page it has almost exactly what I want to do with the date parameters, and the code that I have is almost identical. The problem is that the code is for a VBA in access not excel.
    Last edited by dkannapel; 11-06-2013 at 04:38 PM.

  11. #11
    Registered User
    Join Date
    10-25-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Import Access Query To Excel

    Alansidman:

    I stumbled upon one of your threads from an Access help forum. There you are trying to do the exact same thing I am trying to do now, except you were using 1 date paramater while I am using two (a start and end date). You stated that you changed the dim statements to reflect the changes. Could you please tell me what you did exactly. The code you were using is almost identical to the one I am attempting to use now.

    Thanks

  12. #12
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2507 Win 11
    Posts
    24,918

    Re: Import Access Query To Excel

    Please post the link as I don't recall the situation

  13. #13
    Registered User
    Join Date
    10-25-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    13

  14. #14
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Import Access Query To Excel

    Try this, requires adding reference for Microsoft Access 12.0 Object Library and Microsoft Office 12.0 Access database engine Object to work.
    Please Login or Register  to view this content.

  15. #15
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2507 Win 11
    Posts
    24,918

    Re: Import Access Query To Excel

    In my situation, the reference changes made were from DAO to ADO, so the Dimension statements needed to be corrected accordingly. Whew, that post takes me back to a very old consulting project. The genesis for that code was the earlier link I gave you.

  16. #16
    Registered User
    Join Date
    10-25-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Import Access Query To Excel

    Millz:

    The code fails at "Dim acApp As Access.Application" and give an error message of 'User defined type no defined'. I am running Excel and Access 2010. I am new to all of this so excuse me if I am missing something simple.

  17. #17
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Import Access Query To Excel

    dkannapel: obviously you did not add reference to Access objects. In Visual basic Editor, you have to click on Tools -> References and add the 2 I have mentioned in the previous post.

  18. #18
    Registered User
    Join Date
    10-25-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Import Access Query To Excel

    Millz:

    Sorry your code does work for a query with a set parameter. What I really need is to run a query that has a "start date" and "end date" that the user inputs. Any suggestions?

    Happy Holidays

  19. #19
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Import Access Query To Excel

    You can change the SQL statement accordingly. Something like this as a start maybe.

    Please Login or Register  to view this content.

+ 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. Data import Problem: Access Query to Excel
    By Minder in forum Access Tables & Databases
    Replies: 1
    Last Post: 05-25-2009, 04:23 PM
  3. Import Query in Access to Excel
    By lehainam in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-13-2008, 07:50 PM
  4. Vlookup problem with Access Query import into Excel 2000
    By Neophyte in forum Excel - New Users/Basics
    Replies: 4
    Last Post: 07-16-2006, 10:35 PM
  5. [SOLVED] access query to import to excel
    By jazzydwit in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 07-16-2006, 09:05 PM

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