Results 1 to 1 of 1

Copy or Export an Access Query results back to Excel

Threaded View

  1. #1
    Registered User
    Join Date
    06-20-2004
    Posts
    19

    Copy or Export an Access Query results back to Excel

    It seems like one of the most basic codes involving Excel and Access, but I've been struggling to determine how to copy access query results into excel using VBA.

    I would like to write an excel macro that
    1) opens an access dba file
    2) runs a query
    3) either copy or exports the query results
    4) closes the dba

    #3 is elluding me. I have the following code to open a dba called "Production" which includes a existing query called "Query" and either export or copy the results to an xls called "QueryResults." It hangs on the export line.

    Sub GetData()
      Set appAccess = CreateObject("Access.Application")
      appAccess.OpenCurrentDatabase "F:\Production.mdb"
      appAccess.Visible = True
      appAccess.docmd.SetWarnings True
      docmd.transferSpreadsheet acexport, acSpreadsheetTypeExcel9, _
            "Query", "C:\QueryResults.xls", True, "Sheet1"  :confused:
      appAccess.CloseCurrentDatabase
      appAccess.Quit
      Set appAccess = Nothing
    End Sub
    Thank you in advance for your help and understanding!
    Last edited by VBA Noob; 08-18-2008 at 01:11 PM. Reason: Unwrapped Code

Thread Information

Users Browsing this Thread

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

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