Solved

Raise Event Not working with Multiple Instances of Form

Posted on 2010-11-30
4
537 Views
Last Modified: 2012-05-10
Hello, when I have multiple instances of a form the RaiseEvent only works for the latest instance of the form.  Can anyone tell me what I am doing wrong?

Thanks
Lee
0
Comment
Question by:dccinfrastructure
  • 2
4 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 34240242
>>  Can anyone tell me what I am doing wrong?

Probably not without seeing what your code looks like  :)

How are you calling it?
0
 

Author Comment

by:dccinfrastructure
ID: 34255605
'Form1 calls Form2 when command1 clicked.

'Form1
Private WithEvents f2 As Form2
Dim i As Integer
Dim collForm2 As New Collection


Private Sub Command1_Click()
i = i + 1
Set f2 = New Form2
    f2.initialise i
    f2.Show
    collForm2.Add f2
   
   
End Sub

Private Sub f2_ItemClicked(a As Integer, b As Date)
MsgBox a & "," & b
End Sub


'Form2 RaisesEvent for Form1 when Command1 clicked
'Form2

Public Event ItemClicked(a As Integer, b As Date)
Private m_i As Integer

Public Sub initialise(i As Integer)
    m_i = i
End Sub
Private Sub Command1_Click()
    RaiseEvent ItemClicked(m_i, Now)
End Sub

0
 
LVL 26

Accepted Solution

by:
EDDYKT earned 50 total points
ID: 34256386
your f2 will get override by the new form
you should use class

i.e.
in form1

Dim i As Integer
Dim cls1() As Class1

Private Sub Command1_Click()
i = i + 1
ReDim Preserve cls1(i)
Set cls1(i) = New Class1
cls1(i).initialise i
End Sub

in form2

Public Event ItemClicked(a As Integer, b As Date)
Private m_i As Integer

Public Sub initialise(i As Integer)
    m_i = i
End Sub
Private Sub Command1_Click()
    RaiseEvent ItemClicked(m_i, Now)
End Sub

in class1
Private m_i As Integer
Dim WithEvents f2 As Form2

Public Sub initialise(i As Integer)
    m_i = i
    Set f2 = New Form2
    f2.initialise i
    f2.Show
End Sub

Private Sub f2_ItemClicked(a As Integer, b As Date)
MsgBox a & "," & b
End Sub
0
 

Author Closing Comment

by:dccinfrastructure
ID: 34256493
That worked perfectly.. Thankyou very much.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

749 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