Passing COM objects from VBA

graffy76

New member
Joined
Nov 23, 2009
Messages
3
Programming Experience
10+
Hello,

I have classes I wrote in VBA which I use to manage form / control events for MS Access. I thought I'd try porting them to VB Net...

I built a prototype class with a function that took an Access.Form as a parameter. Of course, in VB Net, and Access form object is not a member of Access.Form, it's a member of Interop.Microsoft.Office.Interop.Access.Form (or something like that).

Anyway, that causes problems when I try to register it using regasm.exe because, of course, COM doesn't understand Interop.Microsoft.Office.etc...

So how can I pass a form object from Access VBA to a VB net function when, in VB net, I have to declare the Form object as a member of a class which COM cannot understand?
 
My original classes provide event handlers using WithEvents. For example, I have a uiControls class which handles events for control objects. I invoke the event handler for an object by typing:

uiControls.Add ctl
uiControls(ctl.Name).Events.OnClick = "MyCustomFunction"

and so on.

The advantage is that I can trap the extra parameters that some events have (like the "Key" and "Mouse" events) without having to limit myself to the form module. Also allows me to change out my callback on the fly, as well as instantiate multiple callbacks for the same control event.

The classes actually work quite well and have gone quite a ways in allowing me to create some nice web2.0 effects for my controls...

As I perused the VB Net features, I see it would let me rewrite my classes *much* more efficiently by programmatically adding handlers as I need them, as well as using inheritance-based polymorphism (which would come in handy in a couple places), and could stand to cut the code in half.

But in order to do that, I have to be able to pass an Access Form object to the VB net class and do my WithEvents management in VB net (with callbacks still stored in the VBA project). In the end, maybe it's not worth the extra effort, but I thought it'd be a great introduction to enhancing VBA development using VB net.
 
Perhaps a better way to phrase the question:

I want to create a COM event sink in VB .NET. I'm having a hard time figuring out how to pass a reference of an existing COM object to the VB .NET sink.

Specifically, if I instance the event sink in VBA and create a control or form in VBA, how do I pass that control or form reference to the VB .NET sink?
 
Back
Top