Have you ever searched for a progress bar for your forms only to run into blind alleys with custom class modules, convoluted forms with complex code behind them?
I've been thinking of the above quote for a week now. I've been using the same progress bar for 15 years + (similiar to yours) and I have a pretty bad obsession with custom classes. It's always hard to come up with ideas for them and this seemed like a good one.
After opening a recordset, you instantiate the class and initialize it
The arguments passed to the class are the record count and a Modulus value. Use a lower Modulus value for small record counts and a higher one for larger record counts.
This helps regulate the speed of the progress bar. Future update to set the Modulus value dynamically.
Code:
Set cPB = New clsPBar1
cPB.InitProgBar rs.RecordCount, 5
In the loop there is a call to the class passing the recordset AbsolutePosition as an argument. To avoid 0 division errors add 1 to AbsolutePosition as it is zero based.
Code:
Do Until rs.EOF
'Your code here
cPB.UpdateBar (rs.AbsolutePosition + 1)
rs.MoveNext
Loop
Works in a for loop too.
Code:
Dim i As Long
Set cPB = New clsPBar1
cPB.InitProgBar 300, 2
For i = 1 To 300
cPB.UpdateBar i
Next i
4 lines of code to implement (including the variable declaration)
Still have some tweaking, testing, and additions in mind but its a start.