Incorporating ActiveX Controls in Access 2003
Before you can incorporate an ActiveX control in your application, you must perform three steps:
Installing an ActiveX Control
When you buy an ActiveX control, it generally has an installation program that copies the OCX file to your Windows system directory. The name of this directory can vary depending on whether you're running Windows 2003, Windows 98, Windows NT, or Windows 2000, and what you named your Windows directory during your operating system installation.
Registering an ActiveX Control
After you have installed the control, you're ready to register it with Access. Often a control is automatically registered during installation, which is true of the Calendar OCX included with Access. OCX controls are registered in the HKEY_LOCAL_MACHINE\SOFTWARE class in the Windows registry (see Figure 21.1). In the figure, the Image List control, registered as ImageListCtrl, is selected.
Figure 21.1. OCX controls in the Windows registry.

If an ActiveX control isn't registered, you can register it by using the ActiveX Controls dialog box. To open this dialog box, choose Tools, ActiveX Controls (see Figure 21.2).
Figure 21.2. Use the ActiveX Controls dialog box to register ActiveX controls.

The ActiveX Controls dialog box lists all the ActiveX controls currently registered in Access. To add an ActiveX control to the list, click Register. This opens the Add ActiveX Control dialog box (see Figure 21.3).
Figure 21.3. The Add ActiveX Control dialog box allows you to locate the ActiveX control you want to register.

Make sure that you're pointing to the directory containing the OCX you want to register. The control you're registering must already be installed; if it hasn't been installed, it won't be on the list. Select the OCX you want to register, and click OK. You then return to the ActiveX Controls dialog box, and the control you selected appears on the list of registered controls. You're ready to include the control on a form.If you no longer plan to use an ActiveX control, you should use the Unregister button, located in the ActiveX Control dialog, which removes the registry entries for controls you don't use.
Adding ActiveX Controls to Forms
After you have registered an ActiveX control, you can include it on your forms. You do this in one of two ways:
- Select the ActiveX control from the toolbox by clicking the More Controls icon.
- Choose ActiveX Control from the Insert menu when you're in Form or Report Design view.
The More Controls tool contains all the ActiveX controls registered by your system. This includes ActiveX controls that are part of Excel, Visual Basic, and any other application that uses ActiveX controls. Some of these controls won't work properly with Access. To determine which controls you can safely include in your application, read the Access Readme file or contact the vendor of the ActiveX control. The More Controls menu is shown in Figure 21.4.
Figure 21.4. The More Controls tool shows you all the ActiveX controls registered on your system.

The menu for the More Controls tool shows all the ActiveX controls installed on the system. You can also use the Insert menu to select an ActiveX control from the Insert ActiveX Control dialog box (see Figure 21.5). After you select a control from the Select an ActiveX Control list box, Access places the control on the form. You can move the control around the form and size it as needed.
Figure 21.5. Use the Insert ActiveX Control dialog box to add an ActiveX control to a form.

After you have placed an ActiveX control on a form, the control is ready to operate in its default format. If you insert the Calendar OCX control in a form and run the form, it looks like Figure 21.6.
Figure 21.6. A Calendar OCX control, shown in Form view, with no properties explicitly set.

The Calendar control can display all the months of the year, along with the corresponding days for each particular month. So far, you haven't set any properties for the calendar, nor have you written code to respond to any of the calendar's events. Setting an ActiveX control's properties, executing an ActiveX control's methods, and responding to an ActiveX control's events are covered in the following sections.
Understanding and Managing the Control Reference in Your Access Application
When you insert an ActiveX control on a form, Access automatically creates a reference to the control's Type Library that appears in the References dialog box (see Figure 21.7). To invoke the References dialog box, choose Tools, References with the Visual Basic Editor active. Note that the full path to the control is stored in this dialog box. For example, Figure 21.7 shows that the Calendar OCX is stored in D:\Program Files\Microsoft Offce\Office. If the OCX is moved, Visual Basic for Applications (VBA) might not be able to resolve the reference. If this happens, you must open the References dialog box and manually remove the check from the reference marked as missing and set a reference to the ActiveX control in its new location.
Figure 21.7. Use the References dialog box to add and remove library references.

If you're distributing an application with ActiveX controls, the application might or might not work without problems. Access does its best to try to resolve references to ActiveX controls. If the controls are in the Windows\System directory or the directory that Access is installed in, Access can automatically resolve the references, even if the application is installed in a different directory on the user's machine than it was on your machine.Remember, not only do ActiveX controls need to be referenced, but they also need to be registered in the Windows registry. If you use the Microsoft Office 2003 Package and Deployment Wizard to distribute your application, the OCXs are automatically registered when the user installs your application. If you don't use the Microsoft Office 2003 Package and Deployment Wizard to distribute your application, you must write code to register the ActiveX control, or the user will have to manually register it.