References > Browse...), I've added in "Microsoft Windows Common Controls 6.0 (SP6)" (c:\windows\syst..." /> References > Browse...), I've added in "Microsoft Windows Common Controls 6.0 (SP6)" (c:\windows\syst..." /> References > Browse...), I've added in "Microsoft Windows Common Controls 6.0 (SP6)" (c:\windows\syst..."/>

How do I declare a reference to an ActiveX "ListView" Control in Access VBA?

2.2k views Asked by At

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) and I've created/inserted an instance of the control "Microsoft ListView Control 6.0 (SP6)" on a Form and given the control the Name "MyListView".

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

I want 'lvw' to point/reference 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:

Public WithEvents lvw As Object
Public WithEvents lvw As Control
Public WithEvents lvw As MSComctlLib.ListView.2

and none works when I

set lvw = MyForm.MyListView

Can anyone explain how I should create the reference (lvw) to the existing object (MyListView)?

2

There are 2 answers

0
PractLogical On

Access can't really handle that sort of thing.

The OnClick should be available on your MyForm though, but you can't see it in the Event tab in properties. ActiveX Controls are too complicated for that. Instead, go into the code and choose MyListView in the combobox on the top left. You'll then find the extended ActiveX events in the combobox on the top right. One of them is ColumnClick.

Not sure what your full intentions are, but if you want to sort of mimic an isolated DecoratedListView class then create a special form that only includes a ListView control and use it as a subform for other forms. You can refer to the ListView from the parent Form as you would any other subform control object. Parent specific code can be run from the listview subform by checking the me.parent.name object which is basically the parent form. You can even call subform's listview events by changing the default Private Sub to Public Sub.

0
BCole On

I can't comment yet, so I'll type it as an answer. Did you look in View, Object Browser to see what methods and properties are available for that object? You should be able to write what you want using that information, assuming what you want is possible.