Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions


Posted on 2000-03-03
Last Modified: 2013-11-26
I have program module as ActiveX DLL.
Now I have wish to run multiple independed instance of that module.
I access DLL through multiuse class which based of input parameters serves
main programs wish (like what exactly to load).
Let's that there is Form1 in DLL. When I call method in class from main program requesting
Form1 to load I creat new Form1.
Set frm = new Form1
Now each form works in its own space.
So far so good, but now I want some response (as needed) back from Form1 to main program.
Therefore I used events. I raise event which causes event in class, then that class raises
event again in order to pass this event futher back to main program.
So far so good, but only last instance of Form1 can do that.
Other previous instances fire event, but event doesn't happen in class.

What am I doing wrong or how should I do it right?
Currently main program creates only once instance of that class and that class then creates multiple forms (for example).

Question by:hpet
  • 5
  • 3
LVL 10

Accepted Solution

caraf_g earned 100 total points
ID: 2579627
"Currently main program creates only once instance of that class and that class then creates multiple forms (for example). "

That's where your problem lies.

What you could do is have an event handler class.

Class1 creates one instance of event handler class

Class1 creates multiple instances of Form1

To each new instance of Form1, Class1 hands an instance of the event handler class.

The eventhandler class has a sub that can be called by form1. Where you want form1 to raise an event, let it call the sub in the eventhandler class instead.

Then let the eventhandler class raise an event.

Finally, Class1 can then respond to the event.

The parameters of the event handler's event should be such that they allow you identify the originating instance of form1.

Hope this helps

LVL 10

Expert Comment

ID: 2579629
Sorry, that should read:

"To each new instance of Form1, Class1 hands that single instance of the event handler class"

Author Comment

ID: 2579885
Thanks caraf_g for fast reply.
I am just trying to implement your suggestion. I created event handle class with HandleEvent sub.
I create one instance of Class1 and then Class1 creates possible multiple Form1.

How do Class1 hand that single instance of event handler class to current Form1 instance?

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

LVL 10

Expert Comment

ID: 2580278
Let's say your event handler is called

Simplest solution:
In your form, declare a public variable

Public objEventHandler As clsEventHandler

In Class1

Private WithEvents mobjEventHandler As clsEventHandler

Private Sub Class_Initialize()

Set mobjEventHandler = New clsEventHandler

End Sub

Private Sub Class_Terminate()

Set mobjEventHandler = Nothing

End Sub

When it instantiates a form

Dim frm As YourForm
Set frm = New YourForm
Set frm.objEventHandler = mobjEventHandler

In the form, when you want to raise the event
objEventHandler.RaiseThatEvent(Me, etc...)

In clsEventHandler:

Public Event ThatEvent(objForm As YourForm, any other parms)

Public Sub RaiseThatEvent(objForm As YourForm, any other parms)

RaiseEvent ThatEvent(objForm, any other parms)

End Sub

And finally, in Class 1

Private Sub mobjEventHandler_ThatEvent(objForm, any other parms)

'Do what you have to do to objForm

End Sub

Hope this helps!

LVL 10

Expert Comment

ID: 2580284
For completeness sake...

In YourForm

Private Sub Form_Terminate()

set objEventHandler = Nothing

End Sub

.... And put some checking code in

If Not objEventHandler Is Nothing


just in case someone forgets to code the last line of
Dim frm As YourForm
Set frm = New YourForm
Set frm.objEventHandler = mobjEventHandler
when they instantiate the form


Author Comment

ID: 2580884
Adjusted points to 100

Author Comment

ID: 2580885

Thanks, you were realy helpful.
Simple solution all together... now that I see it. Too little sleep I guess. Good thing weekend is comming up.

I increased points to 100... thanks


P.S. btw, I am trying to find something out about MSDE data engine. Are you familiar with it? I posted questions few times but nobody even touched it :(
Question is not realy realted to MSDE only. They suggest 5 or less concurrent users before its performance will start degrading. That "concurrent" is realy what I am after, what does it mean exactly for MSDE. Does it mean client connections, does it mean number of simultaneous tasks in MSDE, etc.
LVL 10

Expert Comment

ID: 2580992
Sorry, don't know anything about that. If noone here can help you maybe you could try the newsgroups. Some good ones:

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question