Want to create a button to terminate VBA code if the user feels it is taking too long
Posted on 2008-10-10
I have a function in VBA that opens several recordsets, manipulates data, and writes records to a new table. This process can take several minutes, and I want to give the user the option to cancel the process if they feel it is taking too long.
I have created a form with a "homemade" progress bar that updates as the main function moves through it's logic. I have also put a command button on the form containing the progress bar that says "Cancel". My intention was to use this button to set a flag or perform some other action to stop the main function's execution. However, when the main function is executing, it will update (repaint) the progress bar, but as the user I cannot click the Cancel button - nothing happens, and the function continues until it is finished.
Why can't I click the cancel button? The form is "frozen" until the main function is finished.