The Calendar Control Mimic

Without doubt, one of the most commonly searched for terms on the old Accessory website was “calendar control”. Seems to me that this is a lot of fuss about nothing. The majority of developers just want to be able to trigger a little form from within their own forms, from which a user can select a date, and for that date to then be passed back into the relevant control on the original form.

With this in mind, I've created a simple little modal form that mimics a calendar control quite nicely - it's shown below, together with its key features. This functionality is virtually self-contained, i.e. you only need one extra module to support the cross form functionality (and that just creates one global variable). In other words, all you have to do to use the Accessory Calendar Control Mimic is copy frmCalendar and basCalendar from the sample database, downloadable below, into your database and you're ready to go. What could be easier?

Free download samples: Access 2000 and above | Access 97 - you'll need unzipping software for these downloads, such as WinZip or 7-Zip.

In case you're wondering why a module is needed in Version 2 as well as the form, this was the easiest way for me to add the much-requested support for sub-forms to the Accessory Calendar Control Mimic.

The samples includes a simple demo of how to use the Accessory Calendar Control Mimic but essentially all you do is set a global variable (ctlIn) to the control you want the calendar to populate and open the relevant form (frmCalendar). In the example below a command button called cmdCalendar is being used to launch the Accessory Calendar Control Mimic and put the date returned in a text box on the same form called txtDate.

Private Sub cmdCalendar_Click()
    Set ctlIn = Me.Controls("txtDate")
    DoCmd.OpenForm "frmCalendar"
End Sub

To use the Accessory Calendar Control Mimic all you need to do is copy the frmCalendar form and basCalendar module from the appropriate downloadable sample into your database. Although you are free to use, modify and/or redistribute said form as you wish, please always leave the header referencing Accessory within the underlying VBA. Not only is this courteous, it's also good programming practice to cross-reference your source. Thanks.

No comments:

Post a Comment