Online Book Reader

Home Category

Access Cookbook - Ken Getz [200]

By Root 1951 0
"Cancel". Create an event procedure attached to the button's Click event. (If you're unsure of how to do this, see the Section P.5.5 in the the preface of this book.) Add the following code to the event procedure:

Private Sub cmdCancel_Click( )

mblnCancel = True

End Sub

Add the following global declaration to the global declarations section of the form's module:

Dim mblnCancel As Boolean

Add the following three procedures to the form's module:

Private Sub cmdCancel_Click( )

mblnCancel = True

End Sub

Public Sub InitMeter( _

blnIncludeCancel As Boolean, strTitle As String)

Me.recStatus.Width = 0

Me.lblStatus.Caption = "0% complete"

Me.Caption = strTitle

Me.cmdCancel.Visible = blnIncludeCancel

DoCmd.RepaintObject

mblnCancel = False

End Sub

Public Property Let Value(intValue As Integer)

Me.recStatus.Width = CInt(Me.lblStatus.Width * (intValue / 100))

Me.lblStatus.Caption = Format$(intValue, "##") & "% complete"

DoCmd.RepaintObject

End Property

Public Property Get Cancelled( ) As Boolean

Cancelled = mblnCancel

End Property

Save the form as frmStatusMeter and close it.

Create a new global module and add the following code (or import the module basStatusMeter from 09-10.MDB).

Private Const mconMeterForm = "frmStatusMeter"

Private Function IsOpen(strForm As String)

IsOpen = (SysCmd(acSysCmdGetObjectState, acForm, strForm) > 0)

End Function

Public Sub acbCloseMeter( )

On Error GoTo HandleErr

DoCmd.Close acForm, mconMeterForm

ExitHere:

Exit Sub

HandleErr:

Select Case Err.Number

Case Else

MsgBox "Error#" & Err.Number & ": " & Err.Description, , _

"acbCloseMeter"

End Select

Resume ExitHere

End Sub

Public Sub acbInitMeter(strTitle As String, fIncludeCancel As Boolean)

On Error GoTo HandleErr

DoCmd.OpenForm mconMeterForm

Forms(mconMeterForm).InitMeter fIncludeCancel, strTitle

ExitHere:

Exit Sub

HandleErr:

Select Case Err.Number

Case Else

MsgBox "Error#" & Err.Number & ": " & Err.Description, , _

"acbInitMeter"

End Select

If IsOpen(mconMeterForm) Then

Call acbCloseMeter

End If

Resume ExitHere

End Sub

Public Function acbUpdateMeter(intValue As Integer) As Boolean

On Error GoTo HandleErr

Forms(mconMeterForm).Value = intValue

' Return value is False if cancelled

If Forms(mconMeterForm).Cancelled Then

Call acbCloseMeter

acbUpdateMeter = False

Else

acbUpdateMeter = True

End If

ExitHere:

Exit Function

HandleErr:

Select Case Err.Number

Case Else

MsgBox "Error#" & Err.Number & ": " & Err.Description, , _

"acbUpdateMeter"

End Select

If IsOpen(mconMeterForm) Then

Call acbCloseMeter

End If

Resume ExitHere

End Function

Save and close the global module.

Use the generic status meter in your application


To use the generic status meter in your own applications, follow these steps:

When you wish to initialize the meter, use the following syntax:

Call acbInitMeter(title, flag)

where title is the title you want the status meter to assume, and flag is True (or -1) to display a Cancel button or False (or 0) to not display one. For example, this statement creates a status meter with the title Progress and a Cancel button:

Call acbInitMeter("Progress", True)

To update the meter with a new progress value, use the following syntax:

variable = acbUpdateMeter(value)

where value is an integer between 0 and 100. acbUpdateMeter will place True or False in the return value. If the return value is False, the user has pressed the Cancel button. (The return value will never be False if you choose not to include the Cancel button when initializing the status meter.) For example, to update the meter with a progress setting of 50%, you might call acbUpdateMeter like this:

blnOK = acbUpdateMeter(50)

To close the status meter form, use this syntax:

Call acbCloseMeter

Discussion


You can change the size of the rectangle by manipulating its Width property. The Rectangle control is placed behind a transparent Label control that defines the boundaries of the status meter and

Return Main Page Previous Page Next Page

®Online Book Reader