Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default VBA creating Pivot Table

hi all,
i'm trying to create a pivot table using vba in excel.
everytime i run the code i get an error message stating
the following:

"Run-time error 1004:

An operation that uses the database driver could not be
completed.

If the driver is a MS driver, make sure the driver file
isn't damaged, and if it is, reinstall the driver by
reinstalling MS Query. Etc..."

My code breaks down in the CreatePivotTable section. The
pivot table cache is there, and, I have tested placing the
cache on a worksheet, which works fine. I have
reinstalled excel on a couple of occasions, to no avail.
Don't have any idea how to fix this. I've tried four
different ways to create the pivot table, all with no
luck. Any help is most appreciated. This is my first
time coding for a pivot table so here's my code:

Sub CrPivotTable(colct)
Dim pivCache As PivotCache
Dim pivTab As PivotTable
Dim ptfield(), fields1, fields2() As String
Dim icount, i As Integer
Dim pcRange As Range
Dim rsTest As Recordset

'create pivot table and add necessary fields

'This section creates the worksheet to be updated
'Delete "Report" sheet

Application.DisplayAlerts = False
ActiveWorkbook.Worksheets("Report").Delete
Application.DisplayAlerts = True

Worksheets.Add
ActiveSheet.Name = "Report"


'Define columns
icount = colct

ReDim ptfield(icount), fields2(icount)


For i = icount - 12 To icount
ptfield(i - 12) = Worksheets("Data").Cells(1, (i))
Next

If myRS.EOF Then myRS.MoveFirst


'Define cache

ActiveSheet.Name = "Report"

With ActiveWorkbook.PivotCaches.Add( _
SourceType:=xlExternal)

Set .Recordset = myRS

.CreatePivotTable( _
TableDestination:=Range("A5"), _
TableName:="PTRAX")

End With




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I detail Pivot Table data without creating a table (Excel2007) Skeletiko[_2_] Excel Discussion (Misc queries) 1 May 5th 10 08:22 AM
How can I detail Pivot Table data without creating a table (Excel2007) Skeletiko Excel Discussion (Misc queries) 0 May 5th 10 12:21 AM
creating a report from a table, pivot table not suitable UKMAN Excel Worksheet Functions 1 April 16th 10 08:35 AM
creating a pivot table from 4 pivot tables phyllis W Excel Worksheet Functions 0 October 12th 08 09:52 PM
Creating a Pivot Table lkw441 Charts and Charting in Excel 1 June 7th 05 04:06 AM


All times are GMT +1. The time now is 07:28 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"