title: Event handling class doesn't fire unless I break userform initialization
body: <p>This is a follow-up to the following question:
  <a href="https://stackoverflow.com/questions/45521328/cant-set-userform-keypreview-to-true">Can&#39;t set Userform.KeyPreview to true</a></p>
  
  <p>To recap: the goal is to build a form with some command buttons and a frame containing check boxes. The check boxes are dynamically populated at <code>userform_initialize</code> in the frame so the user can scroll through them. My problem was with keyboard shortcuts. It wasn't possible to brute force write KeyDown handlers for each of the checkboxes because I don't know which ones will exist. Unfortunately, Excel doesn't support <code>KeyPreview</code> so I had to mock up my own version. Thank you to @UGP for giving me promising avenues that seem to work, but not quite...</p>
  
  <p>First, this is my class module called <code>clsReasonPickKP</code>. I create a new instance for each checkbox to listen for <code>KeyDown</code> events:</p>
  
  <pre><code>Option Explicit
  
  Dim WithEvents vChkBx As MSForms.CheckBox
  
  Friend Sub initializeListener(cControl As control)
  Set vChkBx = cControl
  End Sub
  
  Private Sub vChkBx_KeyDown(ByVal keyCode As MSForms.ReturnInteger, ByVal shift As Integer)
  frm2.keyChooser keyCode
  End Sub
  </code></pre>
  
  <p>The line <code>frm2.keyChooser keyCode</code> launches a quick sub located in the userform code module. Code below:</p>
  
  <pre><code>Public Sub keyChooser(ByVal keyCode As MSForms.ReturnInteger)
  Select Case keyCode
      Case vbKeyEscape: cancelBtn_Click
      Case vbKeyReturn: completeDecision_Click
      Case vbKeyN: customizeNote_Click
      Case vbKeyS: resetDecisionNote_Click
      Case vbKeyR: chkRefGrnds_Click
  End Select
  End Sub
  </code></pre>
  
  <p>I've copied the relevant part of the <code>UserForm_Initialize</code> sub below. The loop creates the checkboxes and an event listener for each.</p>
  
  <pre><code>Sub UserForm_Initialize()
  Dim x As Long, maxWidth as Long
  Dim cControl As control
  Dim keyPreviewCollection As New Collection
  Dim keyPreviewer As clsReasonPickKP
  For x = 1 To dTbl.Rows.Count - 1
      Set cControl = chkBoxFrame.Controls.Add("Forms.CheckBox.1", "chkBox" &amp; x, True)
      With cControl
          .AutoSize = True
          .WordWrap = False
          .Left = 10
          .Top = 16 * x - 12
          .Caption = dTbl(x, 1).Value
          If .Width &gt; maxWidth Then maxWidth = .Width
      End With
  Set keyPreviewer = New clsReasonPickKP
  keyPreviewer.initializeListener cControl
  keyPreviewCollection.Add keyPreviewer
  Next x
  'Additional initialization code here
  End Sub
  </code></pre>
  
  <p>The odd thing is that unless I break code some time after <code>keyPreviewCollection.Add keyPreviewer</code>, the listener doesn't seem to handle the event. For example, if I set a break point at <code>Next x</code> or for <code>x &gt; 1</code> and then complete initialization, then when the form is finished initializing and appears the listener calls <code>keyChooser</code> and all is well; if I don't break code like that, it doesn't trap the event or call the sub, etc.  </p>
  
  <p>To trouble-shoot, I've tried not adding <code>keyPreviewer</code> to the collection, and then the listener also doesn't work, no matter if or when I break. It seems adding the object to the collection, and being in code break mode after adding it to the collection, somehow makes the listener trap the event. </p>
  
  <p>Also interesting, if I put a breakpoint in the <code>vChkBx_KeyDown</code> module, it breaks when the event is raised (assuming an appropriate break as described above). After I then run the code, however, it stops handling the <code>KeyDown</code> event when its raised.</p>
  
  <p>In case it helps, I'm currently working in Excel 2010.</p>
  
  <p>Does anybody have any idea what's going on? Any idea how to solve this, even with a different code approach?</p>
  
  <p>Thank you as always for everybody's help.</p>