I am adding ListObject to an Excel 2007 workbook using VBA. ListObject must have a QueryTable behind it, referencing the Access database. The code is as follows:
Dim l As ListObject Dim c As ADODB.Connection Dim r As ADODB.Recordset Set c = New ADODB.Connection c.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=myAccessDatabasePath;Persist Security Info=False;" Set r = New ADODB.Recordset r.Open "Select * From myTable", c Set l = ActiveSheet.ListObjects.Add(xlSrcQuery, r, True, xlYes, Range("A1")) l.QueryTable.Refresh False 'this line causes an error l.QueryTable.Refresh False
Essentially the problem is that I cannot update the table more than once. The Refresh button on the Data and Tabular design ribbons is grayed out. I tried similar code without using Listobjects (i.e. Just QueryTables) and get the same problem. I tried updating the base connection object and getting the same problem again.
I spent all morning at Googling to no avail.
Is this a bug, a designed behavior, or (most likely) am I doing something stupid?
Thank you very much in advance,
Steve
source share