views:

1011

answers:

5
+3  Q: 

VBA + Threads

How can I create a process running on a separate thread in MS Access VBA? I would like to create a process that will just sit and wait for a message.

+4  A: 

Here is a good article that describes COM Threading

bendewey
+2  A: 

Good question, but i think it can't be done.

Mark Nold
+1: correct. You can write a multithreaded component (or use an existing one) and call it from VBA, but VBA is not itself multithreaded.
Joe
A: 

The quickest way I can think of is to create a Form and put an existing or do-it-yourself control on it.

le dorfier
+1  A: 

There is no way to do this directly in VBA itself. Here is a MSDN forum discussion talking about this in detail. Office never exposed any of the VBA extensions for multithreading.

However, you can do this by calling out to the Windows API, or creating your own COM object in VBA (written elsewhere) which performs the multithreaded calls for you. Just make sure to marshall everything back to the calling thread, somehow (probably polling against your COM object, or something similar).

Also, you may want to check out bendewey's link on COM threading, since it's very relevant to this.

Reed Copsey
A: 

If MS Access VBA lets you use forms, drop a timer on a form and set the delay to a really low value, like 10 ms. Then place your code in the timer event function, and it will be executed in a separate thread.

superjoe30
Timers in forms in VBA happen on the main thread. The form uses windows messages to schedule, not a separate thread.
Reed Copsey
Reed, I'm pretty sure this is true for VB6. Is it different for VBA?
superjoe30