Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default VBA Code - Retrieve SQL 2000 data -Pivot Table

I am trying to data stored in sql 2000 server to create Pivot Table - office
2003.
trying to create oledb provider using VBA code. Can anyone tell me what is
wrong with this code. When I open the spreadsheet, it gives me a message
"requested operation requires OLE DB session object, which is not supported
by the current prvider". Also please let me know whether the connection
string is correct or not.

Private Sub Workbook_Open()
Dim conn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim cmd1 As ADODB.Command

Set conn = New ADODB.Connection

With conn
..ConnectionString = "OLEDB;Provider=sqloledb;User Id=xxx;Password=xxx;Data
Source=qqqqq;Initial Catalogue=PATS"
End With
Set cmd1 = New ADODB.Command
Set cmd1.ActiveConnection = conn
With cmd1
..CommandText = "Select RAIL.Adm_Facility, RAIL.County, RAIL.Race from RAIL"
..CommandType = adCmdText
..Execute
End With

Set rst = New ADODB.Recordset
Set rst.ActiveConnection = conn
rst.Open cmd1

Set PTCache = ActiveWorkbook.PivotCaches.Add(SourceType:=xlExter nal)
Set PTCache.Recordset = rst
With PTCache
..CreatePivotTable TableDestination:=Range("A3")
End With

With ActiveSheet.PivotTables("CADATA")
..SmallGrid = False
With .PivotFields("Adm_Facility")
..Orientation = xlRowField
..Position = 1
End With

With .PivotFields("County")
..Orientation = xlColumnField
..Position = 1
End With


With .PivotFields("Race")
..Orientation = xlDataField
..Position = 1
End With

End With

conn.Close
Set cmd1 = Nothing
Set conn = Nothing
Set rst = Nothing
End Sub

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
Retrieve Data to Pivot Table "On Demand" Steve Haack Excel Worksheet Functions 1 May 28th 09 03:57 PM
Run a VB code when you click on the data field of a Pivot Table pgarcia Excel Discussion (Misc queries) 1 March 4th 09 08:27 PM
Lookup data in a variable table & retrieve data from a pivot table Shawna Excel Worksheet Functions 3 October 10th 08 11:11 PM
Excel 2000 Pivot table using offline OLAP CUB as the data source Samson Tang New Users to Excel 1 June 26th 07 04:48 PM
Pivot Table Data Refresh error after upgrade from 2000 to 2003 [email protected] Excel Programming 0 January 4th 05 09:40 PM


All times are GMT +1. The time now is 09:53 AM.

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"