VBA CommandText "application-defined or object-defined error"

goldfish

Well-known Member
Joined
Aug 23, 2005
Messages
712
Code:
Sub QueryUpdate()
Sheets("Totals").PivotTables("PivotTable1").PivotCache.CommandText = "SELECT * FROM Totals"
End SUB

but it gives me the error: "application-defined or object-defined error"

Any idea how I can make this work?

Thanks
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Are you actually using an ODBC connection to a data source with a table called Totals?
 
Upvote 0
Yup, here is more

Code:
DBDir = "C:\Documents and Settings\aft\Q3\ReportTotals"
DBName = "Reports.mdb"
Querystr = "SELECT * FROM Totals"

With Sheets("AddressPivot").PivotTables("PivotTable1").PivotCache
    .Connection = Array( _
        Array("ODBC;DSN=MS Access Database;DBQ=" & DBDir & "\" & DBName & ";"), _
        Array("DefaultDir=" & DBDir & ";DriverId=25;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;") _
    )
    .CommandText = Querystr
    .Refresh
End With

But I get an error when it gets to the .commandtext line. Even the simplified version I posted above didn't work.

Thanks
 
Upvote 0
I'm sorry but I'm no expert in this sort of thing - the code appears, to me anyway, OK and so does the SQL.

Have you considered not using a pivot table?

Access has various methods of summarizing data.:)
 
Upvote 0

Forum statistics

Threads
1,215,053
Messages
6,122,882
Members
449,097
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top