Here is how I like to do it.
Always keep the progress bar a max 100 for percent.
Then in your code, determine the number of records.
Set a variable to keep track of the percentage complete.
Set up a trigger for each percent tick.
Then update the progress bar only when you increment the trigger.
For example:
Dim numItems as Integer
Dim thisItem as Integer
Dim pctTrigger as Integer
Dim thisPct as Integer
numItems = 'Get total number of Items
'Of course, make sure numItems > 0
For ...Item, Do, Loop, etc
'Do work ...
thisItem += 1
thisPct = (thisItem * 100) \ numItems
if thisPct >= pctTrigger then
Call UpdateProgress(thisPct)
Application.DoEvents
pctTrigger += 1
end if
Next item
This way, you only update the progress when necessary.
If you have 100 items, then you get 100 updates.
If you have 1,000,000 items, then you still only get 100 updates (once every
10,000).
Although if you have that many items, you might add an additional rollover
counter for the DoEvents so it happens say every 100 items. That and you would
proly want worker threads anyway.
Pretty much works no matter how many items you have. Since it is an Integer, to
prevent overflows your number of items should be less than about 21.5 million.
But if you have that many to process, then you should be using different methods
anyway.
Gerald