LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Create Excel PivotTable that uses Access query as external data so


Hello to everyone.

I'm trying to achieve the following in Access VBA:
Create an Excel PivotTable that uses an Access query as its external data
source.

Here's the scenario:
In Access, the User runs a Report query.
I would like to give the User the following option:
Create an Excel PivotTable based on the Access Query data, without passing
the data to Excel (with an ADO recordset for example).

Thus, the Excel PivotTable (that will be created in Access VBA) will use the
Query as an External Data Source, and will connect to it with ODBC.

By recording my actions in Excel, i managed to create the Connection string
in Access VBA, i do however get an error message.

Here's the relevant part of my VBA code which manipulates Excel (this code
resides in an Access VBA module):

Public AppXL as Excel.Application

' ...
' (XL has been already initiated, Workbooks added, etc.)

Dim strSQL As String, strQry As String, strCon As String
Dim strAppAccessPath As String, strAppAccessName As String

strQry = "`RQ_ALL INFO (PAR: ANY) - 2`"
strSQL = "SELECT * FROM " & strQry

strAppAccessPath = CurrentProject.Path
strAppAccessName = CurrentProject.Name

strCon = "ODBC;DSN=MS Access Database;"
strCon = strCon & "DBQ=" & strAppAccessPath & "\" & strAppAccessName & ";"
strCon = strCon & "DefaultDir=" & strAppAccessPath & ";"
strCon = _
strCon & "DriverId=25;FIL=MSAccess;MaxBufferSize=2048;PageT imeout=5;"

With AppXL

With .ActiveWorkbook.PivotCaches.Add(SourceType:=xlExte rnal)
.Connection = strCon
.CommandType = xlCmdSql
.CommandText = strSQL
' The next line generates the error
.CreatePivotTable _
TableDestination:=AppXL.ActiveSheet.Cells(3, 1), _
TableName:="PivotTable2", _
DefaultVersion:=xlPivotTableVersion10
End With
.ActiveWorkbook.ShowPivotTableFieldList = True

End With

The error message:
When the code tries to execute the .CreatePivotTable command above, i get
the following error message:

Title:
ODBC Microsoft Access Driver Login Failed
Text:
The database has been place in a state by User 'Admin' on machine
'My_Machine' that prevents it from being open or locked.

Pressing the OK button opens a "Login" dialog box, and trying to loging to
the database won't work (i don't think that's the problem though).

Any comment or insight would be very welcome.

Thank you for your time,
Alex

 
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
Using Excel PivotTable for a huge DataBase from External Data marcher Excel Discussion (Misc queries) 0 September 9th 08 07:59 PM
Get External Data from Access Parameter Query NewUser Excel Discussion (Misc queries) 0 December 1st 07 03:24 AM
Excel 2007 external data query rbaldwin Excel Discussion (Misc queries) 0 November 8th 06 04:34 PM
Access security and excel external data tmountjr[_2_] Excel Programming 1 December 2nd 04 10:04 AM
Retrieving External Data from Access into Excel Vicki Excel Programming 1 May 26th 04 09:20 AM


All times are GMT +1. The time now is 06:25 AM.

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"