Access Cookbook - Ken Getz [199]
' in the Calendar control, close the pop-up calendar form,
' and pass the new date back to the control. Otherwise,
' just return Null.
If IsOpen(acbcCalForm) Then
acbGetDate = Forms(acbcCalForm).CalDate
DoCmd.Close acForm, acbcCalForm
Else
acbGetDate = Null
End If
End Function
acbGetDate sends the calendar a date by using the OpenArgs property of the form (discussed in the Solution in Recipe 9.6) and requests a date from the form by using the CalDate user-defined property created using the Get property procedure. The Load event procedure of frmPopupCal sets the CalDate property to the OpenArgs property. In this case, it's necessary to use the OpenArgs property because you are opening the form in dialog mode, which makes it impossible to manipulate its properties directly.
Calling the acbGetDate wrapper function whenever you wish to use the pop-up calendar form to provide a date to your application ensures that you are always going through a single, consistent entry point. Thus, you never need to bother with opening or closing the form or worry about the names of the controls on frmPopupCal. Just use the following syntax to get a date using the pop-up form:
variable = acbGetDate(current value)
The pop-up calendar's AutoCenter property has been set to Yes so it will always appear in the center of the screen. You may wish to extend acbGetDate with optional left and top parameters so you can precisely position the pop-up calendar form on the screen when it is first opened.
The techniques presented in this solution can be applied to other Microsoft and third-party vendor custom controls, including controls that ship as part of the Visual Basic development environment.
9.10. Create a Generic, Reusable Status Meter
Problem
Access allows you to control the built-in status meter using the SysCmd function, but you have no control over the location or appearance of this status meter. How do you create a status meter that you can control?
Solution
You can create a status meter based on an Access form and control it using VBA routines. The status meter is composed of a Rectangle control and a Label control. By updating the Width property of the rectangle, you can control the meter's progress. Additionally, by updating the Caption property of the label, you can insert messages such as "50% complete." All the internal workings of the control can be encapsulated (hidden) inside the form.
For an example of a programmatically controlled status bar, open and run frmTestStatusMeter from 09-10.MDB (see Figure 9-32). To start the status meter, click the Start button and frmStatusMeter will pop up. If you want the status meter to include a Cancel button, check the Include Cancel button checkbox before clicking the Start button. The status meter will slowly advance to 100% and then close. If you've included a Cancel button, you can click on it at any time to immediately close the status meter and notify the calling form (frmTestStatusMeter) that the cancel has been requested.
Figure 9-32. The frmStatusMeter form
Create a generic status meter
To create a generic status meter for your own application, follow these steps (or skip these steps entirely and import frmStatusMeter and basStatusMeter from 09-10.MDB into your database):
Create a form and set its properties as shown in Table 9-10.
Table 9-10. Property settings for the status bar form
Property
Value
DefaultView
Single Form
ScrollBars
Neither
RecordSelectors
No
NavigationButtons
No
PopUp
Yes
BorderStyle
Thin
Control Box
No
MinMaxButtons
None
Close Button
No
Place a rectangle on the form, name it recStatus, and set its Width property to 0. Set its background color to the color of your choice.
Place a label on the form, name it lblStatus, and set its Width property to the total width you want the status bar to be. Set its Background to Clear. In the Label property, type in "0% Completed".
Add a command button control named cmdCancel with a caption of