Referencing an ActiveX Control in a Class (1 Viewer)

PingPing

New member
Local time
Today, 14:59
Joined
Sep 23, 2009
Messages
1
I'm using Access 2003.

In "References" (Tools > References > Browse...), I've added in "Microsoft Windows Common Controls 6.0 (SP6)" (c:\windows\system32\mscomctl.ocx).

I've then created/inserted an instance of the control "Microsoft ListView Control 6.0 (SP6)" on a Form ("MyForm") and given the listvew control the Name "MyListView".

I wanted to decorate MyListView with some custom methods so I've created a new class module ("DecoratedListView") which contains a member field called "lvw".

I want 'lvw' to point/reference to MyListView, but I don't know what reference type to use in its declaration. Importantly, I also want to capture lvw's ColumnClick event.

I've tried:
Code:
Public WithEvents lvw As Object
Public WithEvents lvw As Control
Public WithEvents lvw As MSComctlLib.ListView.2
Public WithEvents lvw As MSComctlLib.ListView
Public WithEvents lvw As CustomControl

and none works when I

Code:
set lvw = Forms!MyForm.MyListView

The first try (Object) doesn't even compile. I get the exception "Expected: identifier"
The second try (Control) doesn't compile either. I get the exception "Object does not source automation events"
The third try (MSComctlLib.ListView.2) doesn't compile and throws the exception "Expected: end of statement"
The fourth try (MSComctlLib.ListView) compiles but fails at runtime with the exception "Type mismatch". Using TYPENAME() on the control returns "CustomControl".
The fifth try (CustomControl) compiles but fails at runtime with the exception "Object or class does not support the set of events".

I can't believe I'm the first person to have tried to capture an ActiveX Control's events in a separate class, so I must be doing something wrong.

Can anyone tell me if and how I can create the reference?
 
Last edited:

MarkK

bit cruncher
Local time
Today, 06:59
Joined
Mar 17, 2004
Messages
8,186
You need to assign the object in the control to your variable. The CustomControl itself is an Access container that exposes the ActiveX object via the "Object" property of the control, so try . . .
Code:
Private Withevents lvw As mscomctllib.Listview

set lvw = Forms!MyForm.MyListView[B][COLOR="Red"].Object[/COLOR][/B]
 

Users who are viewing this thread

Top Bottom