getting runtime error on VBA when creating totals on a table listobject because it hasnt completed making the table

bobbydaonlybuilder

New Member
Joined
Sep 24, 2020
Messages
5
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
HI All,

So ive a query that runs

//runqry bring back data
//refresh existing activeworkbook.connection (which always uses the same table name "MYTABLE"

then im trying to run the code.. oops sorry missed a bit, I do the following command before the query refresh
Set tbl = Sheets(1).ListObjects("MYTABLE")
tbl.TotalsRowRange.Delete

to remove existing table totals

back to after connection refreshed i try this
Sheets(1).ListObjects("MYTABLE").ShowTotals = True

With Sheets(1).ListObjects("MYTABLE")
' Ive even tried this to no avail....Application.Wait Now() + TimeValue("00:00:03")
.ListColumns("Amount").TotalsCalculation = xlTotalsCalculationSum

It fails everytime with runtime error.. if i hit debug i can then step through it no problem and it works.. it just doesnt exist when the whole thing runs in real time

ANy ideas?

Regards
James
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
James if that doesn't work U can trial this code from Jon Peltier...
Code:
Dim t As Double
t = Timer
Do Until Timer - t > 1
DoEvents
Loop
Dave
 
Upvote 0
James if that doesn't work U can trial this code from Jon Peltier...
Code:
Dim t As Double
t = Timer
Do Until Timer - t > 1
DoEvents
Loop
Dave
just tried that Dave, still no difference, still runtime error but after i debug i can run through no probs
 
Upvote 0
very frustrating this.. I know i can get past it if i read all the data in an array, loop through the array doing the totalling and spit it back out again, but it seems to be a whole lot of work for nothing.. (plus i lose all the handiness of the table object unless i do even more work converting it to a table object after all the above).Cant understand why this is taking so long to register/aknowledge the listobject column
 
Upvote 0
just for anyone that happens across this post with the same issue, i found a solution online (and would have posted up the link only i was using a different computer at the time, sorry i cant credit the person with the answer)
Its because the query is still running in background (even though it may look like it has finished)
so after your:
With ActiveWorkbook.Connections("BOCBACS").ODBCConnection
use the following

brRefresh = .BackgroundQuery
.BackgroundQuery = False
.Refresh
.BackgroundQuery = brRefresh
end with

it solved my issue :)

Thanks for your help Dave
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,680
Members
449,116
Latest member
HypnoFant

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