简体   繁体   中英

Handling ActiveX events on an Access form

I have an ActiveX control for opening and manipulating a proprietary image type. I am able to embed the control in an Access form, and by using the Object Browser am able to ascertain all the class members. The only problem I am having is handling some of the events raised by the control.

For example, from the Object Browser I can see the following event definition:

Event RightClicked()

And when I add the following code to the form:

Private Sub CtrlInstanceName_RightClicked()
  'Anything here
End Sub

Everything works as expected. However, if the event declaration has parameters passed to it, such as:

Event MeasurementUpdated(id as Long)

Adding:

Private Sub CtrlInstanceName_MeasurementUpdated(id as Long)
  'Anything here
End Sub

Produces the following error:

The expression ... you entered as the event property setting produced the following error: Procedure declaration does not match description of event or procedure having the same name.

Even more strange after adding this second handler, all event handlers on the form produce this error, including events raised by the form and other controls on the form.

I have tested the ActiveX control in a C# .NET application and am able to handle the events there (although they don't quite work as expected). In Visual Studio, the function prototypes end up being a little odd with auto-defined event handler class types.

Any ideas on how I need to change the event procedure declaration to avoid this error?

Well like most Friday questions, I later found the answer to this one was rather quite simple.

First, due to my unfamiliarity with the VBA code editor, I did not know that it was possible to create stubs for embedded controls by using the Object combobox above the code. After selecting my control name I selected the MeasurementUpdate event from the procedure combobox.

The correct declaration is simply:

Private Sub CtrlInstanceName_MeasurementUpdated(ByVal id as Long)
  'Anything here
End Sub

The key difference being the ByVal modifier.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM