DISPLAYING A TASK'S PROGRESS WITH THE PROGRESSBAR CONTROL

The ProgressBar ActiveX control provides you with another way to inform users of the progress of processes that might take some time to perform. Using the ProgressBar control to show a task's progress is a great addition to a professional user interface.

Using SysCmd() to Display the Access Progress Bar

In the past, you could use the SysCmd() function to display a progress bar on the Access status bar. Creating a status bar by using SysCmd() is pretty straightforward. On the WindowsCommonControlsProgressBar form, the code in Listing 14.5 is attached to the OnClick event of the cmdShowOldProgress command button.

Listing 14.5. Chap14.mdb: Displaying the Old Access Progress Bar
Private Sub cmdShowOldProgress_Click()

   Dim lngCounter As Long
   Dim varDummy As Variant
   Dim intWait As Integer

   '-- Initialize progress bar
   varDummy = SysCmd(acSysCmdInitMeter, "Old Progress", Me!txtMaximum)

   For lngCounter = Me!txtMinimum To Me!txtMaximum

      '-- Because of fast machines
      For intWait = 1 to 5
         DoEvents
      Next

      '-- Increment progress bar
      varDummy = SysCmd(acSysCmdUpdateMeter, lngCounter)

   Next

   Beep
   MsgBox "Progress bar complete"

   '-- Clear progress bar
   varDummy = SysCmd(acSysCmdClearStatus)

End Sub

Note

The constants used in this routine—acSysCmdInitMeter, acSysCmdUpdateMeter, and acSysCmdClearStatus—are all Access intrinsic constants.


The following steps show how the SysCmd() function is used in Listing 14.5. These steps walk through the cmdShowOldProgress_Click subroutine:

1.
Calling SysCmd() initializes the progress bar. acSysCmdInitMeter and the text to display is passed to SysCmd().

2.
Calling SysCmd(), passing acSysCmdUpdateMeter, and passing the counter value increments the progress bar.

3.
Calling SysCmd() and passing acSysCmdClearStatus clears the progress bar.

Figure 14.12 shows the Access progress bar in action.

Figure 14.12. The Access progress bar using SysCmd() is displayed at the bottom of the screen.


The main issue with using SysCmd() for the Access progress bar is that the progress bar can be displayed only at the bottom of the Access application window. In some cases, you might want to display the progress bar on individual forms.

Using the ActiveX ProgressBar Control

With the ActiveX ProgressBar control, you can place a progress bar on any form you need. On WindowsCommonControlsProgressBar, the same form that contains the sample code for SysCmd(), you find two ProgressBar controls. Figure 14.13 shows the two ProgressBar controls, with the property sheet for the ocxProgressBar1 ProgressBar control.

Figure 14.13. The Progress control has few properties to deal with.


Although you can preset the Minimum and Maximum properties and then use code to increment the control's Value property to increase the progress bar, it's more pragmatic to set the Minimum and Maximum properties at runtime. When you set these properties depends on whether the range for the progress bar will change.

Note

You might notice that the Scrolling property of ocxProgressBar1 has been set to ccSmoothScrolling. This allows you to have the progress bar display a continuous bar rather than the standard blocks. You can see this shortly in Figure 14.14.

Figure 14.14. You can create different-sized and style ProgressBar controls on any form needed.



The code in Listing 14.6 is attached to the OnClick event of the cmdShowOldProgressBar command button.

Listing 14.6. Chap14.mdb: Using the Progress ActiveX Control
Private Sub cmdShowNewProgress_Click()

   Dim intCounter As Integer

   '-- Initialize the Progress controls
   Me!ocxProgressBar1.Min = Me!txtMinimum
   Me!ocxProgressBar1.Max = Me!txtMaximum
   Me!ocxProgressBar2.Min = Me!txtMinimum
   Me!ocxProgressBar2.Max = Me!txtMaximum

   '-- Increment the Value properties for the Progress controls
   For intCounter = Me!txtMinimum To Me!txtMaximum Step Me!txtIncrement

      Me!ocxProgressBar1.Object.Value = intCounter
      Me!ocxProgressBar2.Object.Value = intCounter

   Next intCounter

   Beep
   MsgBox "Progress bar complete"
   '-- Clear the Progress controls
   Me!ocxProgressBar1.Object.Value = 0
   Me!ocxProgressBar2.Object.Value = 0

End Sub

The steps for setting up and updating the ProgressBar control are similar to those used when working with the Access progress bar. The difference is that with the ProgressBar control, you can set the Minimum property as well as the Maximum property.

You can change the values in the txtMinimum, txtMaximum, and txtIncrement text boxes, which are located on the WindowsCommonControlsProgressBar form. Figure 14.14 shows the ProgressBar control in action, with the TextBox controls' values just mentioned set to the defaults.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.130.201