ActiveX Controls


ActiveX controls are additional controls that you can use in your Access forms. You have already worked with built-in controls such as text boxes and command buttons. What if you need a control that is not listed in the standard ToolBox? Numerous additional controls are available, including those already installed on your computer, from Microsoft and other vendors. You can take advantage of them by adding a reference to the control and using the control in your application.

For example, to use a Calendar control, create a new form and, with the form still open, select the Design tab and then click on the ActiveX Controls button on the Controls ribbon. A screen similar to the one shown in Figure 11-11 is displayed. To add the Calendar Control or any other desired control, simply select it in the list of controls and click OK.

image from book
Figure 11-11

When you click OK, the Calendar Control is automatically placed on the new form, as shown in Figure 11-12.

image from book
Figure 11-12

The Calendar Control has properties and events just like any other control, as you can see from the Properties Window shown in Figure 11-13.

image from book
Figure 11-13

Suppose that you want to use the value of the selected date in the calendar, inserting the value into a field in order to spare the user from having to type out the date. Assume in this case that your form contains a text box control.

The following code example illustrates how you would display the selected date in the calendar control in the text box control when the calendar control loses the focus (such as when you click in the text box):

  Private Sub Calendar0_LostFocus() 'set the text box value to the selected calendar value txtSelectedDate = Calendar0.Value End Sub 

When you run the form and select a date in the calendar control, the value in the text box is updated. This is illustrated in Figure 11-14.

image from book
Figure 11-14

You can apply these concepts to any other ActiveX control that you want to work with. You simply add a reference to the control and then drag and drop the control onto the form if Access does not do so for you automatically. You can then work with the control just as you do with any other standard control.




Beginning Access 2007 VBA
Beginning Access 2007 VBA
ISBN: 0470046848
EAN: 2147483647
Year: 2004
Pages: 143

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net