I had some VB code that worked well in the past that pulled data from an Access Query into Excel. After making a few changes in Access, my VB code doesn't appear to work any more.
With ActiveSheet.QueryTables.Add(connection:=Array( _
"OLEDB;Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin; Data Source = " & dbpath & "\KPI Database_Development_BAIN.mdb; Mode=Sha" _
, _
"re Deny Write;Extended Properties="""";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database Password="""";Jet " _
, _
"OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=0;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;J" _
, _
"et OLEDB:New Database Password="""";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy L" _
, _
"ocale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False" _
), Destination:=Range("A1"))
.CommandType = xlCmdTable
.CommandText = Array("Territory Query")
.Name = "KPI Database_Development"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.SourceDataFile = dbpath
.Refresh BackgroundQuery:=False
The last lane regarding the refresh backgroundquery is where the error occur.
The error I get is 'Run Timer Error 1004 Too Few Parameters. Expected 2"
I did make a few minor changes to field names in the table/query in Access, however I thought that since I only referenced the query name in the VB code, that everything should be OK. I changed 2 field names in the table and thus the query.
I've included VB code in the past where the code references specific query tables and fields and realized that the code would need to be updated if a field changed, but wasn't aware that there was something I'd need to take into account using the code above.
Any help around this would be greatly appreciated and valued!