Access Create Excel Pivot Table Data Source

D

ddecost2

I am currently using an Access Frontend with Tables to create several
Excel Pivot tables and charts. Everything is working great but I was
wanting to simplify the code a little if possible. Here is the code
snippit I am looking at changing:

MyDataSetConn = "ODBC;DSN=MS Access Database;" & _
"DBQ=" & datasetpath & "\" & datasetDB & ";" & _
"DefaultDir=" & datasetpath & ";" & _
"DriverId=25;" & _
"FIL=MS Access;" & _
"MaxBufferSize=2048;" & _
"PageTimeout=5)"

With newbook.PivotCaches.Add(SourceType:=xlExternal)
.Connection = MyDataSetConn
.CommandType = xlCmdSql
.CommandText = "SELECT " & _
"IPO_History_tbl.IpoDate, " & _ etc.

The Datasetpath and datasetDb are located in the Access file that this
code is running from. I don't like to hardcoat the paths. I do
suppose that I could get the file path but I would like to go one step
further. Can the .PivotCaches.Add, Point to itself? Why go through
the ODBC connection when the Data is in the current Access file.
Could I do something like this :

Get rid of the "MyDataSetConn =" section and

With newbook.PivotCaches.Add(SourceType:=internal)
.CommandType = xlCmdSql
.CommandText = "SELECT " & _
"IPO_History_tbl.IpoDate, " & _ etc.

Any help would be greatly appreaciated.

Thank you,

Darren
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top