Excel wont refresh until VBA code stops running

Carbon1198

New Member
Joined
May 9, 2021
Messages
1
Office Version
  1. 2010
Platform
  1. Windows
Hi All,

I have an Excel file that executes multiple queries against an SQL Database using ODBCConnection

The code works perfectly when run sequentially, one after each other
However I would like to try run two queries in parallel (at the same time) to make the overall code execute faster


I can do this by setting the ‘BackgroundQuery’ connection property to true (enabling one query to run in the background)

Example:
Query #1: ActiveWorkbook.Connections(“Query_1”).ODBCConnection.BackgroundQuery = True
Query #2: ActiveWorkbook.Connections(“Query_1”).ODBCConnection.BackgroundQuery = False

This works great … However…

Excel does not update / refresh / display the results until after the code stops running (or runs to a break)
Excel will only ‘refresh’ (display) results from queries where BackgroundQuery = False
Excel will NOT ‘refresh’ (display) the query results where .BackgroundQuery = True

Application.ScreenUpdating -or- DoEvents does not work

Any ideas on how to ‘force’ Excel to refresh / release data while the code is still running..? Is this even possible..?


As a side note (and similar problem)… I have seen this same behaviour when trying to update the Object.BackColor of an ActiveX control command button.
The button colour would update perfectly when stepping (F8) through the code – But would not update during ‘running’ code execution.

Any insight into why this happens (or how to work around it) greatly appreciated
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
From your desciption....I'd suggest it isn't possible.
Once the code is controlling a task, it won't do anything else !!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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