WORKING WITH ACTIVEX CONTROLS

When working with ActiveX controls in Access, you will find that they're similar to other Access controls in that they're programmed by using properties, methods, and events.

Not all ActiveX controls are data-bound like standard Access controls. The term data-bound means that the controls have a Control Source property that refers to Access data or can use Access record sources for row sources. When the individual ActiveX controls are discussed in this chapter, the text mentions when the ActiveX controls use data binding and when they don't.

Some ActiveX controls, such as the TabStrip control, require little coding with VBA. Others, such as the TreeView control, can be programmed to be data-driven and therefore made more versatile. Using these controls to their fullest capabilities can take quite a bit of code.

Tip

ActiveX control properties, like standard Access object properties, are updatable at runtime. This way, you can manipulate an ActiveX control as much as any other control.


Looking at the ActiveX Control Shipped with Access

Only one ActiveX control ships in the retail version of Access—the Calendar control. In addition to others, the following controls all ship with the Microsoft Office Developer (MOD):

Animation ImageList StatusBar
Common Dialog ListView TabStrip
FTP ProgressBar Toolbar
Gopher RichTextBox TreeView
HTTP Slider Winsock

In addition to these supported controls are unsupported controls available on various networks.

Note

Certain OCXs used internally by Access show up in the ActiveX control dialogs, but you can't use them. But if you try to place these controls on your form, nothing happens. Some controls in the Access main folder—namely, Flist32.ocx and Imxgrd32.ocx—don't even show up in the ActiveX control dialogs within Access.


There are also third-party ActiveX controls available, including some in the 3rdPartyOcxs folder.

Placing an ActiveX Control on a Form

Although each ActiveX control varies from the next in how it is used, they're all placed on a form in the same manner. To place a control on a form from the database container, follow these steps:

1.
Open an Access database.

2.
Select the Forms tab. The list of forms appears.

3.
Click the New button, located to the right of the form list. The New Form dialog appears.

4.
Select the record source you want from the combo box on the bottom of the New Form dialog.

5.
Click OK. You now have a blank form, displayed in Design mode.

6.
From the Insert menu, choose ActiveX Control. The Insert ActiveX Control dialog appears.(You can also use the More Controls button in the Toolbox.)

7.
Choose the Calendar Control 9.0 from the list of controls, similar to Figure B.1.

Figure B.1. You can insert all ActiveX controls from the Insert ActiveX Control dialog.


8.
Click OK.

The Calendar control is now placed on Form1 (see Figure B.2).

Figure B.2. Although you can see some ActiveX controls, such as the Calendar control, in Design mode, others display only a message.


Now that the ActiveX control is placed on a form, you must customize it for the current application. Although this process changes for each control type—as well as for each application—the method for changing the properties stays the same.

Setting Properties on an ActiveX Control at Design Time

You can set properties in two ways at design time. The first is the same way in which all Access control properties are set—through the Access control property sheet.

Figure B.3 shows the Access Control property sheet (opened by choosing Properties from the View menu) for the Calendar object created on Form1. You can find the properties specific to the type of ActiveX control on the Other tab, just below the Tag property.

Figure B.3. Here's the Access Control property sheet for the new Calendar control.


When you move into an ActiveX control property in the property sheet, the status bar displays the message ActiveX Control specific property because Access doesn't necessarily know what the property is without ActiveX interpreting, which happens during runtime.

Tip

The other way to get to the properties specific to an ActiveX control is to open the control's own property sheet. To open an ActiveX control property sheet, double-click the control or use the control's right-click menu.


The various ActiveX controls have different properties on their property sheets. Figure B.4 shows the property sheet for the Calendar control.

Figure B.4. Here's the ActiveX control property sheet for the Calendar control.


When changing properties of ActiveX controls at runtime, you can use either macros or VBA code. This process is the same as changing properties on any other Access object. When declaring the data type of the ActiveX control in VBA, you can use the Object data type. The following example declares an Object data type for a Calendar control:

Dim ocxCalendar as Object

If the control is referenced (and it is by default when you add it to a form) you can use early binding on the control's .Object property to manipulate it, and you get all of the advantages thereof.

Dim calCalendar as Calendar

Throughout the rest of this chapter, you see some of the different ActiveX controls available to Access developers and how to use them in applications.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.234.83