Control Arrays

G

Guest

control arrays can be used in VB which reduces amount of code that needs to
be entered. is it possible to use the same concept in MS Access which has VB,
because the controls don't have "Index" in their properties and Access does
not allow the user to use the same name for more than one control.
if control arrays can't be used is there anything else that can be used
instead?
thanks.
 
D

Douglas J. Steele

It's possible to use a naming convention for your controls, and simulate
control arrays that way.

For example, if you've got a number of checkboxes, you could name them
chkBox1, chkBox2, chkBox3 and so on. You can then refer to each of them in a
loop like:

Dim ctlCurr As Control
Dim intLoop As Integer

For intLoop = 1 to 10
Set ctlCurr = Me.Controls("chkBox" & intLoop)
' Use ctlCurr to refer to the "current" control
Next intLoop

As to having event procedures and the like, you can write a generic routine
that uses Screen.ActiveControl to determine which control is active, and put
that generic routine as the Event Procedure for all of the controls in the
pseudo control array.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top