lundi 20 avril 2020

How can I pass a checkbox control to a function in VBA (access)

I am using Access 365 and VisualBasic. I have a number of checkboxes on a form that I want to display just a subset of these at a time, so I want to reposition the top of the checkboxes so that no matter which are currently displayed, I can make them line up nicely.

So, I have declared an array of checkboxes that I want to dynamically add those checkboxes to display:

' Array holding the checkboxes that will be displayed, depending upon species, sex, etc.
Dim arrCheckBoxes(cNumCheckboxes) As CheckBox

Then as I determine that a specific check box should be shown, I want to add it to the array at the next available position using this function (which will also update the next available position):

Private Sub AddCheckbox(ByRef arrCheckBoxes() As CheckBox, ByRef chkNew As CheckBox, ByRef intCurrentCheckbox)
    intCurrentCheckbox = intCurrentCheckbox + 1
    arrCheckBoxes(intCurrentCheckbox) = chkNew
End Sub

My problem is that in the code that calls the AddCheckbox function, I cannot figure out how to pass the check box. I am using the following code (CatNeuter is the checkbox from my form).

Call AddCheckbox(arrCheckBoxes, Me.CatNeuter, intCurrentCheckbox)

However, Me.CatNeuter is always 0, so I think I am getting just the value, and not the checkbox control itself. I've tried numerous different methods such as:

Me.Controls!CatNeuter
Me.Controls("CatNeuter")

But I just cannot figure out how to pass the actual checkbox so I can then go through the array and change the Top property for each checkbox.

Regards, Lise




Aucun commentaire:

Enregistrer un commentaire