MS-Access / Getting Started

Speeding up the progress meter display

This routine is called whenever you want to update the progress meter. Generally, you should call the progress meter only when it's likely to be updated. If you know that you have 1,000 records, you might call the meter every 10 records, but if you have 10,000 records, you might call the meter every 100 records.

Although this code is simple, it isn't the best option. In fact, because this code calls the progress meter for every record, it's much slower than the built-in progress meter. A better approach is to call the progress meter every few records:

If (i / lngCounter) * 100 = Int((i / lngCounter) * 100) Then
  SetPMeter i / lngCounter
End If

The If statement checks to see whether the calculation of the completion percentage is an integer (whole number). This calls the progress meter function (SetPMeter) that moves the progress meter rectangle and displays the percentage completed. It's called only 100 times to move the rectangle; even though the If statement is run 50,000 times, you might wonder why the If statement is faster. The reality is that the If statement takes very few resources to process, but a function that changes the width of a rectangle or control, writes to the screen, and then repaints the screen uses a lot of resources - as evidenced by the time to process falling by 90 percent. Follow these steps to integrate the Progress Meter into your application:

  1. Import the Progress Meter form into your application.
  2. Change the code behind the form to interact with your application.
[Previous] [Contents] [Next]