Solved

Raise Event Not working with Multiple Instances of Form

Posted on 2010-11-30
4
529 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 74

Expert Comment

by:käµfm³d 👽
Comment Utility
>>  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
Comment Utility
'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
Comment Utility
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
Comment Utility
That worked perfectly.. Thankyou very much.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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 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…

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now