Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Raise Event Not working with Multiple Instances of Form

Posted on 2010-11-30
4
Medium Priority
?
540 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 200 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
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…
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…
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…
Suggested Courses

597 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