Loading and keeping forms hidden
If you have frequently-displayed forms, consider hiding them rather than closing them. To hide a form, set its Visible property to False. When you need to display the form again, set its Visible property back to True. Hidden forms consume memory, but they display more quickly than forms that are loaded each time they're viewed. In addition, if you're morphing a form or report (changing the way it looks by changing form and control properties), keep the form hidden until all changes are made so that the user doesn't have to watch the changes take place.
Using the hourglass
Use the hourglass cursor when your application performs a task that may take a long time. The hourglass mouse pointer shows the user that the computer is busy and not locked up. Set the Hourglass cursor like this:
DoCmd.Hourglass True 'Use False to return to default cursor
Using the built-in progress meter
In addition to using the hourglass, you should consider using the Access progress meter when performing long routines in a procedure. The progress meter gives constant feedback that your application is busy, and it shows the user progress in the current process.
The following code demonstrates how to use the status-bar progress meter to show the meter starting at 0 percent and increasing to 100 percent, 1 percent at a time. The first example is ProgressMeterUsingBuiltInAccessMeter.
Caution: If you don't display the status bar, you won't see the built-in progress meter when it runs.
The first step for using the percent meter is initializing the meter by calling the SysCmd function:
ReturnValue = SysCmd(acSysCmdInitMeter, "Creating Records", lngCounter)
acSysCmdInitMeter is an Access constant that tells the function to initialize the meter. The second parameter is the text to appear at the left side of the meter. Finally, the last value is the meter's maximum value (in this case, 100); for example, if you were iterating through a loop of 50,000 records, you might set this value to 50,000. Then you can pass the record count at any time to the SysCmd function and Access decides what the meter shows.
After the meter is initialized, pass a value to update the meter. Call the SysCmd function again and pass it the acSysCmdUpdateMeter constant and the new meter value. Remember: The value that you pass to the function is not necessarily the percent displayed by the meter - it can be the number of records processed or any number that represents a percentage from 1 to 100. For example, the meter displays 25 percent if 50,000 records are being processed and the update value is 12,500.
ReturnValue = SysCmd(acSysCmdUpdateMeter, i)
Remove the meter from the status bar after all the records are processed:
ReturnValue = SysCmd(acSysCmdRemoveMeter)
Creating a progress meter as a pop-up form
Open ProgressMeterCallingEveryRecord and click the Search button to see a progress meter implemented as a pop-up form. The bar grows from 0 percent to 100 percent.
This progress meter has some advantages over the standard Microsoft Access progress meter. The
status-bar progress meter isn't always as visible as you'd like. The status bar is always at the bottom
of the screen and is easily overlooked by a user, whereas the pop-up progress meter pops up in the
middle of the screen and is always visible to the user. Plus, the speed of the pop-up meter can be
controlled by updating the meter every x percent.
The progress meter form is created from a few simple controls. It contains a rectangle control, two
label controls, and option group controls.
The code that calls the meter is one simple line buried in the middle of the iteration loop, passing the iteration number and total number of iterations expected. In this example, i is being processed and lngCounter is 50,000.
SetPMeter i / lngCounter
The function SetPMeter consists of only three lines - one to display the rectangle and manipulate its width, one to display the caption on the bar as it grows inside the rectangle, and one to repaint the screen each time so that the bar is animated:
Public Function SetPMeter(p As Single) 'p is percent of total: Me.PMeterBar.Width = p * Me.PMeter.Width Me.PMeterBar.Caption = Format(p, "##%") Me.Repaint End Function
In this tutorial:
- Optimizing Access Applications
- Understanding Module Load on Demand
- Using the .accdb Database File Format
- Distributing .accde Files
- Understanding the Compiled State
- Application's code into a compiled state
- Distributing applications in a compiled or uncompiled state
- Creating a library reference for distributed applications
- Improving Absolute Speed
- Getting the most from your tables
- Getting the most from your queries
- Getting the most from your forms and reports
- Using bitmaps on forms and reports
- Getting the most from your modules
- Using control variables
- Eliminating dead code and unused variables
- Improving Perceived Speed
- Loading and keeping forms hidden
- Speeding up the progress meter display
- Working with Large Access Databases
- Recognizing that compiling and compacting
- Using the decompile option
- Detecting an uncompiled database and automatically recompiling