If a process takes more than a quarter of a second, or maybe half a second we can turn the mouse pointer into the hourglass (or rotating circle on later versions of windows) with this simple code
Expand|Select|Wrap|Line Numbers
- Docmd.HourGlass=True
Expand|Select|Wrap|Line Numbers
- Docmd.HourGlass=False
With that in mind, I set out to create something more advanced than a simple "Please wait..." form, and this is the result.
The downloadable sample consists of 5 objects. A progress form (TSC_ProgressFormSimple) that handles the graphics, a class module (TSC_PF_Simple) that handles all the logic, 2 utilities modules and a form (frm_Test) to try and illustrate intended usage.
You will need to import all but the frm_Test into your application.
To start up the progress form you simply dimension a new class object:
Expand|Select|Wrap|Line Numbers
- 'Init progress form
- Dim oPF As TSC_PF_Simple
- Set oPF = New TSC_PF_Simple
Expand|Select|Wrap|Line Numbers
- 'Show the form
- oPF.Title = "Importing Objects" & vbNewLine & "Please wait..."
- oPF.UpdateTask 0, "Preparing Import"
- oPF.Show
Expand|Select|Wrap|Line Numbers
- oPF.UpdateTask 0.5 , "Importing"
Expand|Select|Wrap|Line Numbers
- Exit_Sub:
- 'Cleanup
- Set oPF = Nothing
Another option is to allow the user to cancel a process (well technically in-between processes when the form is updated). If you set the AllowCancel to true, a cancel button becomes visible and the user can now attempt to cancel. Note that click events only take place when the progress form is updated.
This progress form uses the code by Stephen Leban to autosize the text frames if needed. This means you can use long text strings without missing out.
I hope you enjoy this free sample. Remember that feedback and comments is the fuel that keeps the fire lit.
The problem remaining is that a progress form such as this is only usefull when you have a alot of opereations to run sequentially. It is not that usefull if all you have is a single big query that ages to run, since the progress form can only update graphics, in between queries or other function calls.