ActiveX Controls and Events - MS Access

Using ActiveX controls, you can add extra functionality to your application forms and reports. These controls are available from both Microsoft and other companies (note that not all ActiveX controls will work correctly with Access). You should consult any third-party documentation regarding details for using specific controls. In this section, you will see two examples of popular controls. For an example that demonstrates how to work with the TreeView control, see Chapter, “Using Form Controls and Events.”

ActiveX on 64-bit computers

If you are using the 64-bit version of Microsoft Office, you will not be able to use these 32-bit controls; 64-bit versions of these controls are not available. Both of these points might change in later Service Packs.

Adding a Slider Control

With the Slider control, a user can move a slider to change a value. To add the control, start with a blank form. In Form design, on the Design tab, click ActiveX Controls, as shown in Figure.

Click ActiveX Controls on the Design tab to add an ActiveX control to a form.

Click ActiveX Controls on the Design tab to add an ActiveX control to a form.

In the Insert ActiveX Control window, click the Slider control, as shown in Figure.

Adding an ActiveX control to the form.

Adding an ActiveX control to the form.

Figure shows the slider control in the sample form frmSliderControl.

A form with a Slider control.

A form with a Slider control.

To detect where a user has positioned the slider, you need to capture an event from the slider object. If you look in the references, you might see an entry for the Windows Common Controls. If it is present, then select the reference; if you do not see the reference, you will need to browse to locate the file MSCOMCTL.OCX, as shown in Figure.

Adding the OCX file to create the entry in the references when you do not already have the reference on a 64-bit operating system.

Adding the OCX file to create the entry in the references when you do not already have the reference on a 64-bit operating system.

Figure shows that for a 64-bit system, the file resides in the SysWOW64 directory.

Windows Common Controls 6.0 reference.

Windows Common Controls 6.0 reference.

After adding the reference, you can write the following code on the form to respond to the Scroll event for the slider control:

The UpDown or Spin Control

The UpDown or Spin control consists of two buttons that are used to increase or decrease a number. This control is normally used with a text box to display the value. In Form design, on the Design tab, click ActiveX Controls to display the Insert ActiveX Control window, and then choose the control, as shown in Figure.

Inserting the UpDown ActiveX control on the form.

Inserting the UpDown ActiveX control on the form.

Figure shows the Spin control in the sample form frmUpDownButton.

A form demonstrating the Spin control; the spin control buttons are next to a text box that displays the value.

You want to trap events generated by the buttons, so you need to add a reference to the Windows Common Controls-2. If you do not have this reference (it should already be added when you place the control on the form), then you need to browse and locate the file mscomct2.ocx, as shown in Figure.

Adding the reference to mscomct2.ocx for the spin control.

Adding the reference to mscomct2.ocx for the spin control.

On a 64-bit system, the file resides in the SysWOW64 directory as illustrated in Figure.

Windows Common Controls-2 reference for the spin control.

Windows Common Controls-2 reference for the spin control.

After adding the reference, you can write the following code on the form to respond to these UpDown events when a user clicks one of the spin buttons:


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

MS Access Topics