Search code examples
ms-accessvbams-access-2016

Using generic VBA Access Form for multiple report progress displays


I have several reports / processes that either display lots of progress information or display a small amount of information that I deem is not worth creating an output file, and I want to avoid using a bunch of message boxes. I created a generic form with a list box with the intent of using the following command to display progress:

Forms(formName).lstMessages.AddItem "Status message"

The problem is that nothing displays until sub completion, and in the case of reports that take a minute or so, the generic form actually disappears for a brief period of time.

Short of grabbing every sub / function and putting them into the VBA code for the generic form, is there any way I can "flush" the output so that I get progress displays? Or does anyone have a suggestion on another means of accomplishing what I'm trying to do? Thanks!


Solution

  • Adding this line:

    DoEvents 
    

    after changing the listbox content makes the change visible.

    You need to be aware though, what DoEvents does:

    Yields execution so that the operating system can process other events.

    This can have unforeseen side effects. E.g. if the button that starts your reporting process stays active while the process runs, the user then can click the button again, which will probably wreak havoc. So be sure to disable that button while the process runs.

    See https://msdn.microsoft.com/en-us/library/aa231254(v=vs.60).aspx