Problem with events

D

David Cleave

Hi all

I have a form which is used to run an update process. The update process is
coded in a class module called clsUpdateProcess. clsUpdateProcess is
instantiated by the form to begin the process. As the update process runs, it
generates events which are consumed by the form to provide progress
information to the user.

I want to also have a Word document which summarises the update process. I
have created another class module, clsUpdateDocument, which wraps the
Automation code. I’m a bit confused about how to get clsUpdateDocument to
consume the events produced by clsUpdateProcess. Presumably clsUpdateDocument
needs to declare a reference to the clsUpdateProcess instance in order to
consume its events as follows:

Public WithEvents MyInstance As clsUpdateProcess

But the particular instance I need to refer to is a member of the form’s
class. So how do I point to it?

Or am I going about this the wrong way?

Many thanks

David Cleave
 
R

Robert Morley

Probably the easiest way to resolve the problem is to have a
clsUpdateProcess property for MyInstance in your clsUpdateDocument class.

Public Property Set UpdateProcess(clUpdateProc as clsUpdateProcess)
Set MyInstance = clUpdateProc
End Property

....then in the form, after you instantiate clsUpdateProcess, you would
instantiate clsUpdateDocument and set it to the same object:

Set MyUpdateProcess = New clsUpdateProcess
Set MyUpdateDocument = New clsUpdateDocument
Set MyUpdateDocument.UpdateProcess = MyUpdateProcess

At this point, you have both classes instantiated, and both the form and
clsUpdateDocument will be sinking events for clsUpdateProcess.



Rob
 
D

David Cleave

Working like a charm!

Thank you Rob!

David

Robert Morley said:
Probably the easiest way to resolve the problem is to have a
clsUpdateProcess property for MyInstance in your clsUpdateDocument class.

Public Property Set UpdateProcess(clUpdateProc as clsUpdateProcess)
Set MyInstance = clUpdateProc
End Property

....then in the form, after you instantiate clsUpdateProcess, you would
instantiate clsUpdateDocument and set it to the same object:

Set MyUpdateProcess = New clsUpdateProcess
Set MyUpdateDocument = New clsUpdateDocument
Set MyUpdateDocument.UpdateProcess = MyUpdateProcess

At this point, you have both classes instantiated, and both the form and
clsUpdateDocument will be sinking events for clsUpdateProcess.



Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top