Everytime I think that I get a handle on events in Visual Basic, I always run into a quirk that leaves me baffled. My situation is that I have a class clsButton that functions similar to CommandButtons. I have another class that acts like a collection of buttons to allow me to handle some intermediate code (clsForm) between the basic functions of the buttons and the main form which displays the buttons. My goal is to communication from the very bottom (clsButton) to the very top (frmMain). Apparently, I can raise events to the intermediate level (clsForm), but it will never get to frmMain in this example:
VB Code:
  1. 'clsButton
  2. Private WithEvents coLbl        As Label
  3.  
  4. Public Event MouseClick(viID As Integer, viButton As Integer, viShift As Integer, viX As Single, viY As Single)
  5.  
  6. '.. Various Code ..
  7.  
  8. Private Sub coLbl_MouseDown(viButton As Integer, viShift As Integer, viX As Single, viY As Single)
  9.     If Not bMouseClick Then
  10.         RaiseEvent MouseClick(ID, viButton, viShift, viX, viY)
  11.     End If
  12. End Sub
which ends up in clsForm:
VB Code:
  1. 'clsForm
  2. Public WithEvents foCmdEmp          As clsButton
  3.  
  4. Private WithEvents foForm           As Form
  5.  
  6. Public Event TestEvent()
  7.  
  8. '.. Various Code ..
  9.  
  10. Public Sub TEST_IT()
  11.     RaiseEvent TestEvent
  12. End Sub
  13.  
  14. Public Sub foForm_Click()
  15.     'Set a separate function to test TEST_IT()
  16.     'Call it from this event, it works
  17.     Call TEST_IT  
  18. End Sub
  19.  
  20. Public Sub foCmdEmp_MouseClick(viID As Integer, viButton As Integer, viShift As Integer, viX As Single, viY As Single)
  21.     Call pSet_clsButtonClick(viID)
  22.     Call TEST_IT  ' <--- Fires, TEST_IT is called but no event is sent up
  23. End Sub
I've removed tons of code for this snippet, but it should show that I can get one event to fire in another class module, but it seems you can't fire an event up the hierarchy right after an event has been fired?