Anyone know a "Super DoEvents" or a way to force OLEDBConnection to update its refreshing property?

Tobriand

New Member
Joined
Dec 20, 2012
Messages
7
Hi All,

I've discovered recently that DoEvents doesn't yield to all events - for instance, OLEDBConnection objects do not update whilst VBA code is running when their state has been changed during a .Calculate call made from VBA, even if followed by a DoEvents loop. Aside from using scheduled firing of code (OnTime, SetTimer) - which is suitable some of the time, but not always - are there any APIs anyone can think of that would allow me to manually yield execution totally, and resume mid-procedure - something which would have a similar effect as:

Code:
Private mblnTotalYieldInProcess As Boolean

Public Sub ReCalc()
    If mblnTotalYieldInProcess Then Goto AfterYield

    <... Preceding actions here ...>

    blnInitialState = oCN.OLEDBConnection.Refreshing
    mblnTotalYieldInProcess = True
    Application.OnTime Now, "ReCalc"
    Exit Sub

AfterYield:
    mblnTotalYieldInProcess = False
    blnFinalState = oCN.OLEDBConnection.Refreshing

    <... Rest of code here ...>

End Sub

But a bit less horrible. This approach will almost certainly work, but for a variety of reasons there's a fair chance I might have two of these running asynchronously, and that could get very messy very quickly. I can think of a few hacks to separate them (arrays of UDTs containing a GUID and the boolean, for instance, and an optional strGUID argument for ReCalc) but they feel like hacks. Does anyone know of any better approach than this?

I should also point out, I haven't actually tried Application.OnTime Now; I'm using Application.OnTime Now + CDate("00:00:01"), which obviously is a much longer pause. I'm not 100% certain that scheduling immediate execution will yield enough, though, so completely different approaches would be better.

Thanks in advance,
Toby

EDIT: Formatting
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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