Here’s a good head-scratcher:
I need to create Click events for each control on a popup commandbar which is being created programmatically.
Following the instructions in the excellent “MS Office 2000 VB Programmer’s Guide”, by MS Press (highly recommended) I’ve created an Events class to respond to control click events.
The book’s sample code indicates that the class needs to contain a Public WithEvents declaration for each control on the commandbar. This all works great.
Here’s the tricky part: I don’t know, as I’m writing the code, how many controls there will be on the popup commandbar – the number of controls in the popup is based on current conditions in the user environment and therefore I can’t determine beforehand how many controls it will contain – but I do need a Click event for each control, once the popup is created.
I can easily enough have my code loop through all the controls in the new commandbar, and for each control use a Set statement to link to the control’s events, but the sticking point is that I can’t determine beforehand how many references to controls need to be declared back in the Events class.
Is there an efficient way to do this? – I could arbitrarily say that the popup will contain a max of say 20 items, and write 20 WithEvents declarations, and 20 Control_Click procedures, in the class module, but that doesn’t seem good form.
Gary