Updating a Gauge and Detecting a User Interrupt (Access 95 and 97)

Take the following steps to update a gauge during processing and detect a user interrupt:

1. Start with the project that you created in Loading and Displaying an Image.

2. image\btncmd.gif Select the Command Button control; then add a control to your form. (Cancel the Command Button Wizard when it appears.) Put the control at the top of the form to keep it away from the image.

3. In the Properties box, change the Command Button control's Name property to DoMedian and change the Caption property to Do Median.

4. image\btncmd.gif Select the Command Button control; then add another control to your form. Put the control at the top of the form to keep it away from the image.

5. In the Properties box, change the Command Button control's Name property to Quit and change the Caption property to Quit.

6. Build a gauge consisting of a horizontal line image\btnline2.gif (Line1) inside a rectangle image\btnrctl.gif (Box1). Put the gauge at the top of the form next to the Quit button.

7. Click the Code Window icon on the toolbar.

image\btncode.gif For Access 95.

image\btncode2.gif For Access 97.

8. Select the Declarations module for the General object, and add the following code. In online help, you can select the block of code with the mouse, then press Ctrl-C to copy it.

Dim fEscape As Integer 'Use to indicate the user interrupt
Dim fInProc As Integer 'Use to avoid closing the form during processing

9. Select the Click procedure for the DoMedian object, and add the following code. In online help, you can select the block of code with the mouse, then press Ctrl-C to copy it.

'Enable the ProgressStatus event
Lead1.EnableProgressEvent = True
'Initialize the indicators
fEscape = False 'The user does not want to quit
fInProc = True 'Processing is taking place
'Perform a relatively slow median filter
Lead1.Median 4
'Clean up
fInProc = False 'Processing is no longer taking place
Lead1.ForceRepaint

10. Select the ProgressStatus procedure for the Lead1 object, and add the following code. In online help, you can select the block of code with the mouse, then press Ctrl-C to copy it.

DoEvents 'Detect Windows events
If Not fEscape Then ' Look for the Click on the Quit button
  Me![Line1].Width = Me![Box1].Width * iPercent / 100 'Udpate the gauge
Else
  Lead1.EnableProgressEvent = False 'Cancel the task
End If

11. Select the Click procedure for the Quit object, and add the following code. In online help, you can select the block of code with the mouse, then press Ctrl-C to copy it.

fEscape = True 'The user wants to quit
Me![Line1].Width = 0 'Set the gauge back to the beginning

12. Select the Unload procedure for the Form object, and add the following code. In online help, you can select the block of code with the mouse, then press Ctrl-C to copy it.

If fInProc Then 'If processing is taking place
  Cancel = 1 'Do not let the user close the form
End If

13. image\btncmpl.gif Click the compile button on the toolbar; then close the code window.

14. Close the form designer, saving the changes.

15. With Form1 selected in the Database window, click the Open button to test the form.