View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Mark Mark is offline
external usenet poster
 
Posts: 989
Default PivotTable from a ADODB.Recordset ?

thanks.

I had tried something similar to your first suggestion; didn't seem to
work... maybe I didn't have something quite right.

I'll look at it again, and also look up the help on RecordSet as you suggest.

Thank you.

Mark

"sebastienm" wrote:

Actually, you can also set the recordset to the pivot cache as a data source
for the pivot table... which is what you requested in your question.
An example is given in the xl help for Recordset.
--
Regards,
Sébastien
<http://www.ondemandanalysis.com


"sebastienm" wrote:

Hi,
To set the connection of a pivot table, you would set the
PivotCahce.Connection as follow:
.COnnection="ODBC;" & <odbc_connection_string
or .Connection = "OLEDB;" & <oledb_connection_string

eg something like:
activesheet.pivottables(1).pivotcache.connection= _
"ODBC;" & "Driver={Microsoft ODBC for Oracle}; " & _
"CONNECTSTRING=(DESCRIPTION=" & _
"(ADDRESS=(PROTOCOL=TCP)" & _
"(HOST=HOSTLOC)(PORT=1526))" & _
"(CONNECT_DATA=(SID=DEV4))); uid=USER; pwd=PASS;"

I am not sure you can change Connection after the pivot has been built. If
not, the above code may not work and you would have to set the Connection at
creation time (mod from macro recorder):

With ActiveWorkbook.PivotCaches.Add(SourceType:=xlExter nal)
.Connection = Array( _
Array( "ODBC;" & "Driver={Microsoft ODBC for Oracle}; " & _
"CONNECTSTRING=(DESCRIPTION=" & _
"(ADDRESS=(PROTOCOL=TCP)") _
, Array("(HOST=HOSTLOC)(PORT=1526))" & _
"(CONNECT_DATA=(SID=DEV4))); uid=USER; pwd=PASS;"))

''' ...

Regards,
Sébastien
<http://www.ondemandanalysis.com


"mark" wrote:

Hi.

I've been working with building PivotTables, in vb code, form external
Oracle sources.

I have it working, one way (the xlExternal data source, with the appropriate
.Connection property). But, the way that it is working still requires the
tnsnams.ora file to define what "DEV4" (the name of the database instance)
might mean, etc.

The other day, I was looking on the web and found an article about building
the connect string right into the code, eliminating the need for the
tnsnames.ora file.

The relevant code, minus the database username and password, is he
<<<<<<<<<<<<<<
Dim strCon As String

strCon = "Driver={Microsoft ODBC for Oracle}; " & _
"CONNECTSTRING=(DESCRIPTION=" & _
"(ADDRESS=(PROTOCOL=TCP)" & _
"(HOST=HOSTLOC)(PORT=1526))" & _
"(CONNECT_DATA=(SID=DEV4))); uid=USER; pwd=PASS;"

Dim oCon As Object
Set oCon = CreateObject("ADODB.Connection")

Dim oRs As Object
Set oRs = CreateObject("ADODB.Recordset")

oCon.Open strCon

Set oRs = oCon.Execute("SELECT * from xxaai_test_lab_forecast")
<<<<<<<<<<<<<<<<<<

That works fine, and I can then go through and put that data into a
spreadsheet, should I happen to want to, which I don't.

But, I would like to know how to put that recordset into a pivot table,
somewhat directly.

Can anyone suggest a way to do that?

Thanks,
Mark