Online Book Reader

Home Category

Access Cookbook - Ken Getz [201]

By Root 1819 0
contains the status text. The status meter form is manipulated by three public wrapper functions contained in basStatusMeter: acbInitMeter, acbUpdateMeter, and acbCloseMeter. These functions, in turn, interact with frmStatusMeter through its exposed properties. The wrapper functions know the names of the properties and how to call them, but they know nothing of the inner workings of the form.

acbInitMeter initializes the status meter by opening the status meter form and calling the InitMeter method. At the same time, a parameter is passed that determines if the Cancel button is included on the status meter form:

DoCmd.OpenForm acbcMeterForm

Forms(acbcMeterForm).InitMeter blnIncludeCancel, strTitle

acbUpdateMeter sets the value of the status meter form's UpdateMeter property. It then checks the Cancelled property of the form to determine whether the user has clicked on the Cancel button. If so, it closes the status meter form and returns False to the calling procedure; otherwise it returns True:

Forms(acbcMeterForm).Value = intValue

' Return value is False if cancelled.

If Forms(acbcMeterForm).Cancelled Then

Call acbCloseMeter

acbUpdateMeter = False

Else

acbUpdateMeter = True

End If

acbCloseMeter closes the status meter form using the DoCmd.Close method:

DoCmd.Close acForm, acbcMeterForm

When the InitMeter property is set by some external procedure, the InitMeter procedure runs the following code:

Me.recStatus.Width = 0

Me.lblStatus.Caption = "0% complete"

Me.Caption = strTitle

Me.cmdCancel.Visible = blnIncludeCancel

DoCmd.RepaintObject

mblnCancel = False

This code sets the Width property of the recStatus control to 0 and the Caption property of lblStatus to "0% complete", updates the form's Caption property with the strTitle parameter, and sets the cmdCancel button's Visible property to match the blnIncludeCancel parameter. The code then uses the RepaintObject method to force an update of the screen and resets the mblnCancel module-level global variable to False.

When the UpdateMeter property of the form is set to a value, the following code is executed by the UpdateMeter procedure:

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

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

DoCmd.RepaintObject

This code updates the status meter by changing the width of the recStatus control relative to the width of the lblStatus control. This relative change ensures that the status meter rectangle never exceeds the limits as defined by the width of the lblStatus control. The routine then updates the Caption property of the lblStatus control to a formatted percentage value concatenated to the string "% complete". Once again, the code uses the RepaintObject method to force an update of the screen.

The Cancelled property of the status meter form is handled by the Cancelled Get property procedure. When called by an external procedure, this procedure returns the value of the module-level global mblnCancel variable. This variable, which was initialized to 0 by the IntitMeter Let property procedure, is set to False if the user clicks on the cmdCancel button in the cmdCancel_Click event procedure.

It's a good idea to encapsulate the inner workings of a generic utility form such as frmStatusMeter by keeping all the event procedures private and using procedures to expose a controlled user interface to calling procedures. Getting in the habit of thinking and coding in this object-oriented way will allow you to create generic components that you can reuse over and over again.

The pop-up status meter form's AutoCenter property has been set to Yes, so it will always appear in the center of the screen. You may wish to extend acbInitMeter with optional left and top parameters so you can precisely position the form on the screen when it is first opened.

Chapter 10. Multiuser Applications


Access offers native support, right out of the box, for multiuser applications. But this additional power brings with it some additional problems, chiefly those of coordinating multiple

Return Main Page Previous Page Next Page

®Online Book Reader