Test Case: C7.03.00

Title: Calling Method, Setting Property in VBA in Access

Platforms: Windows NT 3.51, 4.0, Windows 95
Requirements: Office97 app, OLE control
Sample Apps: Microsoft Access97, MFC Control Wizard generated control
Test Category: CONTROL

Overview:

This sample code illustrates adding a 'test' control, and calling methods and setting properties on that control from VBA. Obviously the properties and methods will vary by control.

You cannot programmatically create an ActiveX control of any particular class on an Access form. Access has a CreateControl function that permits you to create a generic ActiveX Control, but it does not let you specify the control's class. You can however copy the OleData property of an existing control

into other controls.

 

This means that you must use the Access UI to place at least one instance of your

ActiveX Control onto any form somewhere in your Access database. Once you've done that,

you will be able to programmatically place copies of that control onto any number of Access forms

at runtime.

 

for the purpose of these tests, we are just finding the control on an existing "form1", where we have added it by hand, and calling it's custom methods and setting properties

Steps:

 

'------------------------------------

'Access

Sub Test()

'You cannot programmatically create an ActiveX control of any

'particular class on an Access form. Access has a CreateControl

'function that permits you to create a generic ActiveX Control,

'but it does not let you specify the control's class.

'You can however copy the OleData property of an existing control

'into other controls.

 

'This means that you must use the Access UI

'to place at least one instance of your

'ActiveX Control onto any form somewhere in your

'Access database. Once you've done that,

'you will be able to programmatically place

'copies of that control onto any number of Access forms

'at runtime.

 

'for the purpose of these tests, we are just finding the control on an

'existing "form1", where we have added it by hand,

'and calling it's custom methods and setting properties

 

Dim frm As Form

Set frm = Forms("form1")

Dim ctl As Control

Dim b As Integer

' Enumerate Controls collection.

For Each ctl In frm.Controls

' Check to see if control is Custom control

If ctl.ControlType = acCustomControl Then

Debug.Print ctl.Name

b = ctl.MyMethod()

ctl.Caption = "test"

End If

Next ctl

End Sub

 

Result:

Control added to slide, properties and methods invoked successfully.

Summary:

This tests whether the control can be manipulated from VBA.