Stop Macro in progress with cancel button

J

Joe G.

I've created a database with tables, forms and macros that will connect to
computers in our network and pull the add/remove programs list so we can get
a list of installed software on our PCs.

Everything works fine, except if I want to cancel the scan while it's in
progress.
I have a form with a list of all computers. I select the computers I want to
scan and it loops through passing the pc name and other info to a macro. The
macro then connects to each computer, gets the add/remove programs & puts it
in a table. Between macro scans, the form runs DoEvents.

I've added a cancel button that changes a global variable to false. The form
looks at this variable each time it runs the macro to see if the scan has
been canceled.

The problem is that the form is frozen while the macro runs (it can take
anywhere from 10 to 40 seconds), so I have to hold down the cancel button
until the macro has completed and the form has recognized it. It doesn't
always recognize the button is pushed either.

My question is... What's a better way to do this?
My first thought was to use threads so the form would continue to work while
the macros ran. Then it could simply kill the thread to cancel the scan.
However I don't know how to program threads.

Any thoughts?
TIA!
 
J

Joe G.

Thanks for your response!

Ok, Maybe I used the wrong word.
I'm used to calling them macros from Excel.

It's VB code. I'm running a function from a module.

Sorry for the confusion.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top