title: Creating a Class to Handle Access Form Control Events
body: <p>I'm trying to create a Class which will handle multiple Control Events in Access. This is to save the repetition of typing out many lines of identical code.</p>
  
  <p>I've followed the answer located on the following page, but with a few adjustments to tailor it to Access rahter than Excel.</p>
  
  <p><a href="https://stackoverflow.com/questions/12883265/how-to-assign-a-common-procedure-for-multiple-buttons">How to assign a common procedure for multiple buttons?</a></p>
  
  <p>My Class code below:</p>
  
  <pre><code>Option Compare Database
  
  Public WithEvents ct As Access.CommandButton 'Changed object type to something recognised by Access
  
  Public Sub ct_Click()
      MsgBox ct.Name &amp; " clicked!"
  End Sub
  </code></pre>
  
  <p>My Form code below:</p>
  
  <pre><code>Option Compare Database
  Private listenerCollection As New Collection
  Private Sub Form_Load()
  Dim ctItem
  Dim listener As clListener
  
  For Each ctItem In Me.Controls
      If ctItem.ControlType = acCommandButton Then 'Changed to test whether control is a Command Button
          Set listener = New clListener
          Set listener.ct = ctItem
          listenerCollection.Add listener
      End If
  Next
  
  End Sub
  </code></pre>
  
  <p>I have noted with comments where I have made changes to the (working) Excel code. I think the problem comes with the object declaration in the Class. Note: no errors are thrown during this procedure; it simply doesn't trigger the event.</p>
  
  <p>Thanks in advance!</p>
  
  <p>Edit:</p>
  
  <p>I've since narrowed the problem down to there being no '[Event Procedure]' in the 'On Click' Event. If I add it manually, the Class works as expected. Obviously, I don't want to have to add these manually - it defeats the object. Any ideas how I would go about this?</p>