Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error in Creating EXCEL Pivot Table using ACCESS DataBase

Status
Not open for further replies.

vivek1431

Technical User
Jul 12, 2003
2
US
Hello:

I am trying to create a pivot table in EXCEL using an ACCESS Database. However, I am getting an error which says -Runtime Error 1004 : [Microsoft][ODBC Microsoft ACCESS Driver] Could not find the file 'unknown'.

This is a VBA code straight from John Walkenbach's book. It wuns when I run the code from CD provided in the book. However, it does not run when I save the code and ACCESS Database on the c: drive.

Following is the code:
Sub CreatePivotTableFromDB()
Dim PTCache As PivotCache
Dim PT As PivotTable

' Delete PivotSheet if it exists
On Error Resume Next
Application.DisplayAlerts = False
Sheets("PivotSheet").Delete
On Error GoTo 0

' Create a Pivot Cache
Set PTCache = ActiveWorkbook.PivotCaches.Add _
(SourceType:=xlExternal)

' Path to database file
DBFile = ThisWorkbook.Path & "\budget.mdb"

' Connection String
ConString = "ODBC;DSN=MS Access Database;DBQ=" & DBFile

' QueryString
QueryString = "SELECT * FROM `" & ThisWorkbook.Path & _
"\BUDGET`.Budget Budget"

With PTCache
.Connection = ConString
.CommandText = QueryString
End With

' Add new worksheet
Worksheets.Add
ActiveSheet.Name = "PivotSheet"

' Create pivot table
Set PT = PTCache.CreatePivotTable( _
TableDestination:=Sheets("PivotSheet").Range("A1"), _
TableName:="BudgetPivot")

' Add fields
With PT
' Add fields
.PivotFields("DEPARTMENT").Orientation = xlRowField
.PivotFields("MONTH").Orientation = xlColumnField
.PivotFields("DIVISION").Orientation = xlPageField
.PivotFields("BUDGET").Orientation = xlDataField
.PivotFields("ACTUAL").Orientation = xlDataField
End With
End Sub

Can somebody help me?

Thanks!
 
Thanks for the reply. It stops at following step:

' Create pivot table
Set PT = PTCache.CreatePivotTable( _
TableDestination:=Sheets("PivotSheet").Range("A1"), _
TableName:="BudgetPivot")

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top