Control Arrays - how to simulate?

  • Thread starter Thread starter Michael
  • Start date Start date
M

Michael

I have a form with a tab control having 10 pages. Each of the 10 pages can
have 10 comand buttons. I can create the code to populat the click events
behind each of the command buttons, but at the end of the day, I have
hundreds of repetitive events.

If Icould create a control array, it would be much more elegant.... but
Access 2002 doen't support it.

Any suggestions on a workaround or simulating it?

Thanks
Michael
 
No control arrays in Access. What you can do instead is
create a generic function that takes the control as the
argument. eg

Private Sub btnMyButton_Click()
MySub Me.btnMyButton
End Sub

Private Sub MySub(btnControl as Button)
'Do your code here
End Function
 
You might consider using an option group; add your controls to the group,
and assign each one an integer OptionValue.

Now clicking one of your controls will fire the group's AfterUpdate event,
and the group's value will become the OptionValue of the control you
clicked.

BTW 10 controls in a group is not a very large number.
You'll probably get better performance with the 10 controls already on your
form, and just showing/hiding them, rather than creating the code
dynamically.
 
Well it is a page with a 10 page tab control. Each page has 21 command
buttons. So all in all it is about 200 odd controls! Do you think this is
enough reason to look at control array simulations / option group type
approaches?
 
I certainly wouldn't place 200 controls on a form programmatically.

If each page looks the same as each other page, I'd tend to use a tab strip
instead of a tab control, and just re-purpose the same 21 command buttons.
You can write an all-purpose function (as suggested by another user) and
pass it the name of the control and the setting of the tab control, so you
can tell which selection has been made.

HTH
- Turtle
 
Back
Top