Just another couple of comments:
Of course
Dim mtxtCtl as TextBox(7,5)
is incorrect. Proper usage would be:
Dim mtxtCtl(7, 5) As TextBox
The other big advantage of control arrays is in writing event procedures. To avoid having to write an event procedure for each control in an array of controls, Access provides the facility to code an appropriately scoped function procedure. For example, if a grid of textboxes contains a series of file names that you would like to open with a double click on the text box, you can write a private function in the code behind the form and call it by setting a property in the property sheet of the control. In this case, if you write a function named dblClkRun, you can set the On Dbl Click property to =dblClkRun(). When you copy and paste this control to build an array, the property remains set just as the length and width remain set in the copy and the control is hooked to the event procedure without writing additional code. For procedures like mouse over, mouse move, click, double click, got focus, before/after update, you can pass in a reference to the control to be operated on:
=dblClkRun([Screen].[ActiveControl])
which is not subject to any of the ususal issues surrounding using the ActiveControl as those kinds of events only apply to the active control.
Alternatively, you can edit individual control event procedure properties by adding a specific parameter that the function can use to identify the control on which to operate. While not as easy to implement as simply copying and pasting a control, it is a simple matter to edit the property sheet such that each control passes in a name or a number:
txt1 could use: =dblClkRun(1)
txt2 : =dblClkRun(2)
txt3 : =dblClkRun(3)
or some variation therof.
In an application I've written, I have some textboxes that display dates. Given the confustion that often arises from international date formatting issues, I thought it expedient to use a calendar form from which dates could be chosen. In the pursuit of consistency, I chose a textbox size and date format and set the properties and created a single function procedure that is passed a reference to the active control. When I need a date control on a form, all that is necessary is to copy an existing instance of the control to the target form and all the functionality required to pop the calendar and set the date in the control is encapsulated with the control. And that is the case notwithstanding that the control is on a form, a sub form or a subsubform. There is no need to parse form names or level of form as the procedure receives a reference to the actual control regardless of the container.
There are other controls such as numeric calculation fields that benefit from popping a calculator and receiving the calculation value that benefit from this approach but its most useful application is in the case of arrays of controls.
Ciao
Jürgen Welz
Edmonton, Alberta
[email protected]