Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default "acessor flags" creating pivot table from recordset

I'm using ADO to create a recordset which I'm trying to use to create a
pivot table. The code is below. I get error "One or more accessor flags
were invalid" on the CreatePivotTable line. I know the recordset has data.

TIA,

Wolfie

Dim rsData As ADODB.Recordset
Dim szConnect As String
Dim szSQL As String
Dim objPivotCache As PivotCache
Dim objPivotTable As PivotTable

' Create connection string
szConnect = "Provider=SQLOLEDB; Data Source=MyServer;;User ID=myuser; " & _
"password=mypassword"

' Create the SQL statement
szSQL = Worksheets("SQL_ActPlan").Range("A100").Value

' Create the Recordset object and run the query.
Set rsData = New ADODB.Recordset
rsData.Open szSQL, szConnect, adOpenForwardOnly, _
adLockReadOnly, adCmdText

' Make sure we got records back
If Not rsData.EOF Then
' Use the record set for the pivot table
Set objPivotCache = ActiveWorkbook.PivotCaches.Add(xlExternal)
Set objPivotCache.Recordset = rsData2
With objPivotCache
.CreatePivotTable TableDestination:="R7C1", _
TableName:="PivotTable1", ReadData:=True
End With
rsData2.Close
End If


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default "acessor flags" creating pivot table from recordset

The issue here was in the following line

If Not rsData.EOF Then

Apparently this code does something to the recordset so that the pivotcache
is unable to read it. Freaky right!? I commented it out and it now works.
Apparently testing BOF and RecordCount causes the same problem.

The credit for this find goes to the Wrox Excel VBA books (which are
excellent) and their brilliant authors.

Wolfie


"Wolfie" wrote in message
...
I'm using ADO to create a recordset which I'm trying to use to create a
pivot table. The code is below. I get error "One or more accessor flags
were invalid" on the CreatePivotTable line. I know the recordset has
data.

TIA,

Wolfie

Dim rsData As ADODB.Recordset
Dim szConnect As String
Dim szSQL As String
Dim objPivotCache As PivotCache
Dim objPivotTable As PivotTable

' Create connection string
szConnect = "Provider=SQLOLEDB; Data Source=MyServer;;User ID=myuser; " &
_
"password=mypassword"

' Create the SQL statement
szSQL = Worksheets("SQL_ActPlan").Range("A100").Value

' Create the Recordset object and run the query.
Set rsData = New ADODB.Recordset
rsData.Open szSQL, szConnect, adOpenForwardOnly, _
adLockReadOnly, adCmdText

' Make sure we got records back
If Not rsData.EOF Then
' Use the record set for the pivot table
Set objPivotCache = ActiveWorkbook.PivotCaches.Add(xlExternal)
Set objPivotCache.Recordset = rsData2
With objPivotCache
.CreatePivotTable TableDestination:="R7C1", _
TableName:="PivotTable1", ReadData:=True
End With
rsData2.Close
End If



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
Create Pivot Table Data with Column "Sum" rather than "count" defa Johnny_99[_2_] Excel Discussion (Misc queries) 2 January 2nd 10 04:25 PM
Pivot Table Report Filter - "OR" instead of "AND" Multiple Filters tommcbrny Excel Discussion (Misc queries) 1 October 29th 09 04:08 AM
Pivot table "Group and Show Details" vs. "SubTotals" pgchop Excel Programming 0 February 1st 06 08:29 AM
Copy recordset from an Access "make table" query Laurie[_4_] Excel Programming 1 February 5th 04 10:45 AM
Creating small "recordset" or sorting a numeric 1-dim array Anthony Cravero Excel Programming 0 December 19th 03 07:36 PM


All times are GMT +1. The time now is 01:55 PM.

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

About Us

"It's about Microsoft Excel"