?
Solved

Raise Event Not working with Multiple Instances of Form

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month8 days, 20 hours left to enroll

765 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