On a form I will have a dozen or more checkboxes that determine if specific documents are required for this client. Each checkbox will have "associated" with it one or more other controls that hold data about when that document was sent, received, the score, etc.
The goal is to have the checkbox's AfterUpdate event Sub set the .enabled value of the associated controls ("Friends") on or off to match the checkbox's status.
The authors of
Microsoft Access 2010 Programmer's Reference suggest creating a subclass of the standard checkbox object which allows you to add another parameter (.Friends) which is an array of the form's controls that are associated with each instance of the checkbox object.
Here's where I'm stuck
First when assigning the array of objects to the subclassed checkbox object's .Friends parameter. In the "Public Property Let Friends(oArray As Variant)" on the next line I get: "Can't assign to an array"
Second I'm not sure I'm passing the associated object reference in the right way (in the form's OnOpen event Sub) so as to be able to use them in the custom class's "mCkBx_AfterUpdate()".
Here is the code from 1) the form's VBA code and 2) the class module.
Code:
Option Compare Database
Option Explicit
Public mCK01 As New clsMyCkBox
Private Sub Form_Open(Cancel As Integer)
'Setup all the CheckBox classes
Set mCK01.sjrCkBox = Me.ckDocA
'Set the .Friends array for each special checkbox (those obj's that get turned on & off with this checkbox)
Dim aAr(2) As Variant
aAr(0) = "Me.txtDocADtSent" 'or should this be "Form_frmDocControl.txtDocADtSent" ??
aAr(1) = "Me.txtDocADtRecvd"
mCK01.Friends = aAr
End Sub
Private Sub Form_Unload(Cancel As Integer)
'Cleanup special Checkbox class instances
Set mCK01 = Nothing
End Sub
Code:
Option Compare Database
Option Explicit
'Declare the class instance
Private WithEvents mCkBx As CheckBox
'The private variable behind the Friends parameter (dimensioned smaller than will be in the final application)
Private maFriends(2) As Variant
Public Property Get sjrCkBox() As CheckBox
Set sjrCheckBox = mCkBx
End Property
Public Property Set sjrCkBox(objCkBx As CheckBox)
Set mCkBx = objCkBx
mCkBx.AfterUpdate = "[Event Procedure]"
End Property
Public Property Let Friends(oArray As Variant)
maFriends = oArray
End Property
Private Sub mCkBx_AfterUpdate()
Dim bOn As Boolean
Dim i As Integer
bOn = Me.sjrCkBox.Value
For i = 0 To UBound(maFriends)
'set the enabled value for each object to match the Checkbox value
maFriends(i).Enabled = bOn
Next
End Sub