Results 1 to 3 of 3
  1. #1
    runthis457 is offline Novice
    Windows 7 64bit Access 2000
    Join Date
    Feb 2011
    Posts
    16

    Exporting from a Access Table to Excel PivotTable

    I was wondering how I would go about exporting data from a table in access to a pivotTable in Excel. I know how to set up a Pivot Table so that is nothing new for me, but the question is how to set up the Pivot Table one time, and then at the simple press of a button in access the data from my access table is imported into my PivotTable and I can view the most up to date information.

  2. #2
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,529

  3. #3
    runthis457 is offline Novice
    Windows 7 64bit Access 2000
    Join Date
    Feb 2011
    Posts
    16
    It looks like this code should do the trick:

    Code:
    Dim rst As DAO.Recordset
        Dim customQuery As String
        Dim cnt As Integer
        
        Dim appExcel As Excel.Application
        Dim wbk As Excel.Workbook
        Dim wks As Excel.Worksheet
        Dim rng As Excel.Range
        
        Dim fileName As String
    
        Set appExcel = Excel.Application
        appExcel.Visible = True
        Set wbk = appExcel.Workbooks.Add
        Set wks = wbk.Worksheets(1)
        Set rng = wks.Range("A2:I4001")
        wks.Cells(1, 1).Value = "Generating data..."
        
        Set rst = CurrentDb.OpenRecordset(customQuery)
        If (rst.RecordCount > 0) Then
            cnt = 1
            For Each fld In rst.Fields
                wks.Cells(1, cnt).Value = fld.Name
                cnt = cnt + 1
            Next fld
            Call rng.CopyFromRecordset(rst, 4000, 26)
        End If
        
        fileName = ExportDir & "\Molenproductie" & DateTimeFrom & "-" & DateTimeTo & ".xls"
        wks.SaveAs (fileName)
        
        rst.Close
    
        Set rst = Nothing
    However, how would I keep it from overwriting the data each time I export? Like I want it to append the data to it. What I am trying to do is create a monthly report, but I need to export the data daily. So every day (Mon - Fri) I need to export the data, but have it appended (Tues, appended to Mon and so on).

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

Similar Threads

  1. Exporting more than 65000 Access rows to Excel
    By TonyBender in forum Import/Export Data
    Replies: 8
    Last Post: 08-22-2013, 04:56 PM
  2. Error Message after exporting MS Access Table
    By samjoseph in forum Access
    Replies: 1
    Last Post: 02-22-2010, 04:08 PM
  3. Replies: 2
    Last Post: 01-24-2010, 09:19 PM
  4. Exporting Access queries to Excel
    By dbDamo in forum Import/Export Data
    Replies: 2
    Last Post: 09-22-2009, 01:42 AM
  5. Replies: 0
    Last Post: 06-05-2009, 10:47 AM

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