Solved

Raise Event Not working with Multiple Instances of Form

Posted on 2010-11-30
4
538 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
[X]
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
  • 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

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.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

726 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