Access Controls  «Prev  Next»
Lesson 8The Calendar ActiveX Control
ObjectiveAdd the Calendar Control to a Form, binding it to a Data Source.

Calendar ActiveX Control

Binding a Calendar Control to a field in a Microsoft Access database involves several steps that enable users to select dates from a graphical calendar interface, which then updates a corresponding date field in the database. This enhances user experience and data entry accuracy. Follow these steps to integrate and bind a Calendar Control to your Microsoft Access database:
  1. Open Your Form in Design View:
    • Begin by opening the form where you want to include the Calendar Control in Design View. This view allows you to modify the layout and properties of the form elements.
  2. Insert the Calendar Control:
    • In the Design View, locate the toolbox which contains various controls that you can add to your form. If the Calendar Control is not visible in the toolbox, you might need to add it by selecting "More Controls" (usually symbolized by an icon with a wrench and a hammer) and finding the Microsoft Calendar Control from the list. Once found, select it and then click on the form where you want to place the control.
  3. Set the Control Properties:
    • With the Calendar Control selected, open its property sheet. If the property sheet is not already open, you can access it by right-clicking the control and selecting "Properties" or by clicking the "Property Sheet" button in the Design tab of the ribbon.
    • In the property sheet, locate the "Name" property and give your Calendar Control a meaningful name, as this will be used later in the VBA code to reference the control.
  4. Bind the Control to a Database Field:
    • Binding the Calendar Control directly to a database field is not as straightforward as binding standard form controls because the Calendar Control does not inherently support direct data binding. Instead, you will use VBA code to synchronize the control's value with a field in your database.
    • Open the form's module by right-clicking on a blank area of the form in Design View and selecting "Build Event" > "Code Builder". In the VBA editor, you will write event procedures for the Calendar Control to update the database field when a user selects a date.
  5. Write VBA Code for Date Selection:
    • In the form's module, create a subroutine for the Calendar Control's `AfterUpdate` event. This subroutine will be executed every time a user selects a date on the calendar. The code will look something like this:
       Private Sub YourCalendarControlName_AfterUpdate()
      	 Me.YourDateFieldName.Value = Me.YourCalendarControlName.Value
       End Sub
       
    • Replace `YourCalendarControlName` with the name you assigned to the Calendar Control and `YourDateFieldName` with the name of the field in your form's record source that you want to update with the selected date.
  6. Synchronize the Form Field with the Calendar (Optional):
    • If you want the Calendar Control to display the correct date when navigating through records, you'll need to add code to the form's `Current` event, which runs whenever a new record is loaded into the form:
      Private Sub Form_Current()
      On Error Resume Next  ' In case there is no date set
      Me.YourCalendarControlName.Value = Me.YourDateFieldName.Value
      End Sub
      
    • This ensures that the Calendar Control displays the date from the currently selected record.
  7. Test the Functionality:
    • After implementing the code, switch your form back to Form View and test the functionality. Select a date from the Calendar Control and verify that the corresponding date field in the database is updated accordingly. Also, navigate through records to ensure the Calendar Control updates its displayed date based on the current record's date field.
  8. Save Your Work:
    • Once you have verified that the Calendar Control is functioning as expected, save your form and the underlying VBA code.

By following these steps, you integrate a Calendar Control into your Microsoft Access application, enhancing the user interface and ensuring accurate date entries. This method relies on VBA to bridge the gap between the user interface and the database, providing a flexible approach to managing date inputs in your Access forms.

Making sure the Calendar ActiveX control is available

The Calendar control is a very intuitive yet powerful control. It is so easy to use that it is the only ActiveX control featured in the Access box itself. To use the Calendar ActiveX control, you need to make sure you have the control registered. To find out about this, you can pick ActiveX Controls from the Tools menu. Then scroll down the available ActiveX controls to Calendar Control 8.0. You can see an example of the ActiveX Controls dialog here:

Microsoft ActiveX Controls in MS Access Database:

While technically still available, the use of Microsoft ActiveX Controls in MS Access Databases is **strongly discouraged** due to security concerns and limited support:
Availability:
  1. Technically Available: ActiveX Controls are included in some older versions of Microsoft Access (2003 and earlier) and the ActiveX Design Objects component in Access 2007. However, they are not actively developed or supported by Microsoft anymore.
  2. Not Available in newer versions: ActiveX Controls are **not directly available** in newer versions of MS Access (2010 and onwards).

Usability and Security Concerns:
  1. Security Risks: ActiveX Controls can pose security risks as they are external components that can potentially access your system and data. Microsoft has actively discouraged their use due to vulnerabilities and exploits.
  2. Limited Support: Due to being discontinued, ActiveX Controls might not function properly on modern operating systems or with newer versions of Microsoft Office. You might encounter compatibility issues and lack technical support.
  3. Alternatives Available: Microsoft recommends using built-in Access features and modern alternatives like VBA code, Ribbon customizations, and Access Web Apps for better performance and security.

Recommended Course of Action:
  1. Avoid using ActiveX Controls: If you are starting a new Access project, it's best to avoid using ActiveX Controls altogether. Opt for safer and more supported alternatives offered by Access.
  2. Migrate existing databases: If you have existing Access databases using ActiveX Controls, it's highly recommended to migrate them to use alternative approaches supported in newer versions. This will enhance security and future-proof your application.

In conclusion, while technically available in some older versions, ActiveX Controls are not recommended for new or existing MS Access databases due to security concerns and lack of support. Opt for safer and more supported alternatives offered by Access for better performance and security.
ActiveX Controls dialog
ActiveX Controls dialog

If you cannot see the control in the list, you will need to reinstall Access and make sure you choose to have the Calendar ActiveX control included.

Adding a bound Calendar control to a form

Once the Calendar control is available, adding it to a form is a piece of cake. Follow these steps:
  1. Create a form bound to a record source containing a date-type field, and open it in Design view.
  2. Display the field list.
  3. Click on the ActiveX control button
    Builder button
    Builder button

    , located in the toolbox.
  4. Pick the Calendar control from the list.
  5. Now take the cursor and highlight the field you want to use to bind the Calendar control.
  6. Holding the left mouse button down, drag and drop the field onto the form.

The Calendar control will now be displayed on the form, and its Control Source property will contain the field you want.
Besides having some properties displayed on the Other tab of the property sheet, ActiveX controls have their own properties. You can open ActiveX control property sheets by double-clicking in the center of the control itself.

Properties of Calendar Control

Calendar Properties
Calendar Properties

1)GeneralThis tab is for the overall control features.
2)Font Lets you set various fonts on the Calendar control.
3)ColorYou can set the colors for different parts of the calendar.
4)ValueWhen not bound to a field, this will be the date displayed initially.
5)First DayLets you specify the first day of the week for the calendar.
6)Day LengthThis specifies whether to display one letter for heading (short), three letters (medium), or the whole word (long).
7)Month LengthThis specifies whether to display three letters for each month (short) or the whole word (long).
8)Grid Cell EffectHow you want the cells on the calendar to look: Flat, Raised, or Sunken?
9)ShowUse these properties for even more control over the look of the calendar.

Calendar Properties

View the diagram below to see the property sheet for the Calendar ActiveX control.
Builder button
  1. This tab is for the overall control features
  2. Lets you set various fonts on the Calendar control.
  3. You can set the colors for different parts of the calendar.
  4. When not bound to a field, this will be the date displayed initially.
  5. Lets you specify the first day of the week for the calendar.
  6. This specifies whether to display one letter for heading (short), three letters (medium), or the whole word (long).
  7. This specifies whether to display three letters for each month (short) or the whole word (long).
  8. How you want the cells on the calendar to look: Flat, Raised, or Sunken?
  9. Use thes properties for even more control over the look of the calendar.

In the next lesson, we will conclude this module.

SEMrush Software