vba - Excel Querytable Refresh only works once -
i adding listobject excel 2007 workbook using vba. listobject have querytable behind it, linking access database. code looks this:
dim l listobject dim c adodb.connection dim r 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 * mytable", c set l = activesheet.listobjects.add(xlsrcquery, r, true, xlyes, range("a1")) l.querytable.refresh false 'this line causes error l.querytable.refresh false
essentially problem cannot refresh table more once. refresh button on both data , table design ribbons greyed out. have tried similar code without using listobjects (i.e. querytables) , same problem. have tried refreshing underlying connection object , again, same problem.
i've spent morning googling no avail.
is bug, designed behaviour or (most likely) doing stupid?
many in advance,
steve
ok, got work. macro recorder (thanks suggestion dick) useful once.
dim s worksheet dim l listobject set s = activesheet set l = s.listobjects.add(xlsrcexternal, "oledb;provider=microsoft.ace.oledb.12.0;data source=mydatabasepath;", true, xlyes, range("a1")) l.querytable.commandtype = xlcmdtable l.querytable.commandtext = "mytable" l.querytable.refresh false 'this works! l.querytable.refresh false
Comments
Post a Comment