Option Compare Database
Option Explicit
Private m_ControlArray As Collection
Public Event MouseDown(TheControl As Access.Control, Button As Integer, Shift As Integer, x As Single, y As Single)
Public Event MouseMove(TheControl As Access.Control, Button As Integer, Shift As Integer, x As Single, y As Single)
Public Event MouseUp(TheControl As Access.Control, Button As Integer, Shift As Integer, x As Single, y As Single)
Public Event KeyDown(TheControl As Access.Control, KeyCode As Integer, Shift As Integer)
Public Event KeyPress(TheControl As Access.Control, KeyAscii As Integer)
Public Event KeyUp(TheControl As Access.Control, KeyCode As Integer, Shift As Integer)
Public Function Add(TheControl As Access.Control) As ControlArrayItem
  'create a new Pet and add to collection
  Dim NewControlArrayItem As New ControlArrayItem
  NewControlArrayItem.Initialize TheControl, Me
  m_ControlArray.Add NewControlArrayItem, TheControl.Name
  Set Add = NewControlArrayItem
End Function
Public Sub Add_ControlArrayItem(TheControlArrayItem As ControlArrayItem)
  'I also add a second Add to allow you to build the object and then assign it
   m_ControlArray.Add TheControlArrayItem, TheControlArrayItem.ControlArrayItem.Name
End Sub
Public Property Get Count() As Long
  Count = m_ControlArray.Count
End Property
'Public Property Get NewEnum() As IUnknown
'    'Attribute NewEnum.VB_UserMemId = -4
'    'Attribute NewEnum.VB_MemberFlags = "40"
'    'This is allows you to iterate the collection "For Each pet in pets"
'   Set NewEnum = m_Pets.[_NewEnum]
'End Property
Public Property Get Item(Name_Or_Index As Variant) As ControlArrayItem
  'Attribute Item.VB_UserMemId = 0
  'Export the class and uncomment the below in a text editer to allow this to be the default property
  'Then reimport
  Set Item = m_ControlArray.Item(Name_Or_Index)
End Property
Sub Remove(Name_Or_Index As Variant)
  'remove this person from collection
  'The name is the key of the collection
  m_ControlArray.Remove Name_Or_Index
End Sub
Public Property Get ToString() As String
  Dim strOut As String
  Dim i As Integer
  For i = 1 To Me.Count
    strOut = strOut & Me.Item(i).ControlArrayItem.Name & vbCrLf
  Next i
  ToString = strOut
End Property
'-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
'---------------------------------------------------------------------------- Class Methods to Raise Common Events ---------------------------------------------------------------------------------
Public Sub CA_MouseDown(TheControl As Control, Button As Integer, Shift As Integer, x As Single, y As Single)
 RaiseEvent MouseDown(TheControl, Button, Shift, x, y)
End Sub
Public Sub CA_MouseMove(TheControl As Control, Button As Integer, Shift As Integer, x As Single, y As Single)
 RaiseEvent MouseMove(TheControl, Button, Shift, x, y)
End Sub
Public Sub CA_MouseUp(TheControl As Control, Button As Integer, Shift As Integer, x As Single, y As Single)
  RaiseEvent MouseUp(TheControl, Button, Shift, x, y)
End Sub
Public Sub CA_KeyDown(TheControl As Access.Control, KeyCode As Integer, Shift As Integer)
 RaiseEvent KeyDown(TheControl, KeyCode, Shift)
End Sub
Public Sub CA_KeyPress(TheControl As Access.Control, KeyAscii As Integer)
 RaiseEvent KeyPress(TheControl, KeyAscii)
End Sub
Public Sub CA_KeyUp(TheControl As Access.Control, KeyCode As Integer, Shift As Integer)
  RaiseEvent KeyUp(TheControl, KeyCode, Shift)
End Sub
'----------------------------------------------- All Classes Have 2 Events Initialize and Terminate --------
Private Sub Class_Initialize()
'Happens when the class is instantiated not related to the fake Initialize method
'Do things here that you want to run on opening
  Set m_ControlArray = New Collection
End Sub
Private Sub Class_Terminate()
  'Should set the object class properties to nothing
  Set m_ControlArray = Nothing
End Sub