Finding Properties and Methods of an ActiveX Control in Microsoft Access
Provided by: FMS Development Team
Ever wonder why you can't see all of the Properties and Methods of an
ActiveX control in intelli-sense? Here's a tip of how to get these to show
in intelli-sense.
When you add an ActiveX control to your application, you're
adding new functionality that has a different set of properties in addition
to the standard properties of controls in the host (we'll be using MS Access
for our example and discussion). While the Microsoft Access properties show up when
referencing the object via code, the object's properties do not show until
you reference it in a slightly different way.
For instance, to reference a control through standard code,
you would make your code look something like the following:
Me.txtMyStandardTextBox.Value = ""
Note that as soon as you type in the period (.) character, a
list of properties and methods show in intellisense. Doing this with an
ActiveX control will also show the standard list of properties and methods
available through the host environment.
For the remainder of our examples we will be using a FMS
TextEffects control (from the
Total Access Components
product line) named "fmsTefCtl".
Me.fmsTefCtl.Value = ""
Ok, so is that the Value property we want to use? Not
really. While MS Access and the FMS Text Effects control will accept that
property being set, the control's object property - also named "Value" - is
the one we really want to set. So, what's the difference? MS Access has a
standard set of properties available for controls. These properties are
shown in intellisense for controls compliant with MS Access. However, an
ActiveX control may also have it's own property that happens to have the
same name as the MS Access property. The Value property of the FMS Text
Effects control is a prime example of this.
To get to the Control Object's properties, you need to
reference the code in another way. First you dimension a variable to be the
Object type. In other words your code would look like this:
Dim MyTextEffectsCtl As fmstext
Note that in order to see the "fmstext" object in code after
the "As" statement, you must have a reference set to the Total Access
Components OCX file. To set a reference to this file, simply go to the IDE
Toolbar named "Tools, References" and set a reference to the one named
"Total Access Components 2000". What? You can't see it? Ok, use the 'Browse'
Button on the References Dialog and find the .ocx named "tacomp90.ocx".
You'll need to be sure you are viewing 'Files of Type' that are listed as
"ActiveX Controls (*.ocx)" in the dropdown on this dialog. (Hint: The
tacomp90.ocx is in your Windows System folder if you have the product
installed).
Once you have dimensioned the variable as the Object, you
can now set that object to the name of the control on the form using the
.Object property:
Set MyTextEffectsCtl = fmsTefCtl.Object
Note that the .Object syntax is very important here. You are
now able to reference the Object's properties that may be different from the
standard MS Access properties you were able to see before. Now you can use
the Variable named MyTextEffectsCtl in order to see the FMS Text Effects
Control properties specific to the control:
MyTextEffectsCtl.Value =
""
Note that all of the properties and methods specific to this
ActiveX control object are now available via intellisense!
You can do the same thing on SubForms in MS Access by
referencing the SubForm Control.Controls property. Note, you should use the
Subform Control name, and not the name of the Subform itself. Something like
this:
Dim
MyTextEffectsCtl_subform As fmstext
Set
MyTextEffectsCtl_subform = _
me.SubFormControlName.Controls("fmsTefCtlOnTheSubForm").Object
MyTextEffectsCtl_subform.Value = ""
No more guessing if you spelled something properly or if that property or
method exists for the control on main forms or subforms. Happy coding!
Return to the tips page.
|