Microsoft KB Archive/283030

= MOD2000: How to Use the ProgressBar ActiveX Control =

Article ID: 283030

Article Last Modified on 8/9/2001

-

APPLIES TO


 * Microsoft Office 2000 Developer Edition

-



This article was previously published under Q283030



SUMMARY
Advanced: Requires expert coding, interoperability, and multiuser skills.

You can use the Microsoft ProgressBar control to show the progress of an operation toward completion. A ProgressBar control has a range and a current position. This article demonstrates how you can use the Max, Min, and Value properties of the ProgressBar control in a Microsoft Access 2000 database.

This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access.



MORE INFORMATION
 Start Microsoft Access 2000, and then open any database. In the Database window, click the Forms tab, and then click New to create a new form that is not based on any table or query. On the File menu, click Save As, and then save the form as frmProgressBar.  Add three unbound text boxes to the frmProgressBar form, and then set their properties as follows:       Name: txtMin Default Value: 10 Validation Rule: Is Not Null Validation Text: Please Enter a Numerical Value

Name: txtMax Default Value: 5000 Validation Rule: Is Not Null Validation Text: Please Enter a Numerical Value

Name: txtStep Default Value: 10 Validation Rule: Is Not Null Validation Text: Please Enter a Numerical Value   On the Insert menu, click ActiveX Control, and then insert the Microsoft ProgressBar Control, version 5.0. Set its properties as follows:       Name: CtlProgress Width: 1.95 Height: .15   Add two command buttons, and then set their properties as follows: <pre class="fixed_text">      Name: cmdRun Caption: Run

Name: cmdClear Caption: Clear </li>  Insert a label, and then set its properties as follows: <pre class="fixed_text">      Name: lblComplete Caption: 0% Complete Visible: No                   </li> Right-click the Run command button, and then click Build Event on the menu that appears.</li> In the Choose Builder dialog box, click Code Builder, and then click OK.</li>  Type the following event procedure in the module window: Private Sub cmdRun_Click

Dim prg As ProgressBar Dim IntValue As Long Dim fmin As TextBox, fmax As TextBox, fstep As TextBox Dim strComplete As String Dim Complete As Label

Set fmin = Forms!frmProgressBar!txtMin Set fmax = Forms!frmProgressBar!txtMax Set fstep = Forms!frmProgressBar!txtStep Set prg = Me!CtlProgress.Object Set Complete = Me!lblComplete

' If the txtMin textbox contains a non-numeric value ' or a number less than 0, force the user to     ' re-enter data in correct format.

If Val(fmin) <= 0 Then MsgBox &quot;Please enter a positive numerical value above 0 &quot; & _ &quot;in the Minimum text box.&quot; fmin = Null fmin.SetFocus Exit Sub End If

' If the txtMax text box contains a non-numeric ' value or a number less than the value in txtMin, ' force the user to re-enter data in correct format.

If Val(fmax) <= 0 Or Val(fmax) <= fmin Then MsgBox &quot;Please enter a positive numerical value above &quot; & _ fmin & &quot; in the Maximum textbox.&quot; fmax = Null fmax.SetFocus Exit Sub End If

' If txtStep contains a non-numeric value or a number less ' than 1, force the user to re-enter data in correct format.

If Val(fstep) < 1 Then MsgBox &quot;Please enter a number less than or equal &quot; & _ &quot;to 1 in the Step text box.&quot; fstep = Null fstep.SetFocus Exit Sub End If

' The maximum value for the MAX property of a progress bar ' is 10,000; if the number entered in txtMax is over 10,000, ' set the MAX property to 10,000. Otherwise, set the MAX ' property to whatever the user has entered.

If fmax > 10000 Then prg.Max = 10000 Else prg.Max = fmax End If

' The maximum value for the MIN property of a progress bar ' is also 10,000; if the number entered in txtMin is     ' greater than 10,000, set the MIN property to 9,999 ' so it is still less than the MAX property. Otherwise, ' set the MIN property to whatever the user has entered.

If fmin > 10000 Then prg.Min = 9999 Else prg.Min = fmin End If

IntValue = fmin

' Increment the progress bar and % complete label as long as the ' Value assigned to it is less than or equal to the MAX property ' of the progress bar.

Complete.Visible = True

Do        IntValue = IntValue + Me!txtStep If IntValue >= prg.Max Then IntValue = prg.Max End If        prg.Value = IntValue strComplete = Format((prg.Value / prg.Max) * 100, &quot;##&quot;) & _ &quot; % Complete&quot; Complete.Caption = strComplete DoCmd.RepaintObject Loop While IntValue < prg.Max

End Sub </li> Right-click the Clear command button, and then click Build Event on the menu that appears.</li> In the Choose Builder dialog box, click Code Builder, and then click OK.</li>  Type the following event procedure in the module window: Private Sub cmdClear_Click

Dim prg As ProgressBar Dim Complete As Label

Set prg = Me!CtlProgress.Object Set Complete = Me!lblComplete

' Clear the Progress Bar by setting its value to the ' Control's MIN property; then hide the Complete label.

prg.Value = prg.Min Complete.Visible = False

End Sub </li> On the Debug menu, click Compile Loaded Modules.</li> Save the form, and then switch the form to Form view.</li> Click Run. Note that the ProgressBar fills while the label control shows the progress as a percentage.</li></ol>

<div class="references_section">