Results 1 to 4 of 4
  1. #1
    Red Fox is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2014
    Posts
    3

    Exclamation Create pivot table in Excel from MS Access using VBA

    Hello!



    Please can you help to improve the VBA code. It's necessary to create pivot table in Excel from MS Access using VBA.

    The VBA code stops running on this line:

    HTML Code:
    Set PTCache = .ActiveWorkbook.PivotCaches.Add _      
           (SourceType:=xlDatabase, _      
           SourceData:=.ActiveWorkbook.Sheets("Raw_Data").Range(SourcePivot))
    Access file is attached.

    Thanks in advance.
    Attached Files Attached Files

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,621
    Weird message when opening ReportForm: There is no object in this control. I hit OK (twice) and form finally opens.

    Instead of code to set label caption, could use a textbox with expression in ControlSource. Set as Enabled No. I removed the Activate procedure and don't get error.

    However, get that same error on the DatePicker code when I run the ReportButton event. I comment those 2 lines.

    Now get error message: Object variable or With Block variable not set. - triggered by Set MyQueryDef line. Why modify QueryDef?

    What does p variable represent?

    Why open query object?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Red Fox is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2014
    Posts
    3
    Thanks for the reply! Sorry, the attached file wasn't correct. I resolved the problem, but got a new one. Now the VBA recoder stops to work on the following lines:

    Code:
                     With .ActiveSheet.PivotTables("PivotTable")
                            .PivotFields("Group").Orientation = xlRowField
                            .PivotFields("Group").Position = 1
    New file is attached. Thanks for the reply.
    Attached Files Attached Files

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,621
    Open db and get error "There is no object in this control." - twice and when I try to run the button event because of date picker code. Commented code.

    I get error "Unable to set the Position Property of the PivotField class".

    The only example I can find that seems relevant declares and sets PivotItem and PivotField object variables http://stackoverflow.com/questions/1...in-pivot-table
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Access VBA Excel Pivot Table Formatting
    By Tomlon in forum Programming
    Replies: 1
    Last Post: 02-07-2013, 02:28 PM
  2. Access 2010 VBA Creating Pivot Table in Excel
    By Tomlon in forum Programming
    Replies: 1
    Last Post: 02-07-2013, 02:25 PM
  3. Export to Excel from Pivot Table in Access 2010
    By nicon2k in forum Import/Export Data
    Replies: 0
    Last Post: 04-10-2012, 07:02 AM
  4. Pivot table - access to excel
    By antagonia in forum Access
    Replies: 3
    Last Post: 12-16-2011, 01:57 PM
  5. Export Access Pivot Table to Excel
    By graviz in forum Programming
    Replies: 1
    Last Post: 11-13-2009, 07:30 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