control array in access?

G

George

HI, I am working on an Access 2002 database on an XP Home edition computer.

It seem Access does not support controls array, like
txt(1),txt(2),...,txt(8), I have to create a series text boxes:
txt1, txt2 txt3,...txt8. that's really incontinent.
I am just wondering if there is any way to iterate these text boxes like an
array or like a collection, or "for each textbox in txt"?

Thanks!

George
 
D

Dirk Goldgar

George said:
HI, I am working on an Access 2002 database on an XP Home edition
computer.

It seem Access does not support controls array, like
txt(1),txt(2),...,txt(8), I have to create a series text boxes:
txt1, txt2 txt3,...txt8. that's really incontinent.

Hmm, I don't think "incontinent" is the word you intended. :)
I am just wondering if there is any way to iterate these text boxes
like an array or like a collection, or "for each textbox in txt"?

You're right that Access doesn't have control arrays. Normally the
continuous-forms feature does what control arrays are used for in VB.

However, you can get a similar effect by numbering your controls
sequentially -- txt1, txt2 txt3,...txt8, as you suggested -- and then
building the control name dynamically in a loop, like this:

Dim i As Integer

For i = 1 to 8
Debug.Print Me.Controls("txt" & i)
' or do what you want with Me.Controls("txt" & i) ...
Next i
 
S

sps

This concept works great when the control is being
accessed from somewhere else. When dealing with several
controls with events attached, it still requires that you
have multiple "on click" routines. Is there a better way
around this?
Steve.
 
S

sps

This concept works great when the control is being
accessed from somewhere else. When dealing with several
controls with events attached, it still requires that you
have multiple "on click" routines. Is there a better way
around this?
Steve.
 
P

PC Datasheet

If the code is the same for all the controls, you can do this:

Create a Function in a standard module that contains the code for the controls.
Something like:
MyFunction()
<<Code For Controls>>
End Function

Then open the form in design view and select the controls that need to run the
code. Open properties to the Events tab. Right there at the appropriate event,
enter:
=MyFunction

All the controls that were selected will now run the code in MyFunction when the
event for that control fires.
 
D

Dirk Goldgar

sps said:
This concept works great when the control is being
accessed from somewhere else. When dealing with several
controls with events attached, it still requires that you
have multiple "on click" routines. Is there a better way
around this?
Steve.

PC Datasheet's suggestion is about the best you can do. If you need to,
the function you write and share among the controls can use
Me.ActiveControl or Screen.ActiveControl to determine for which control
the event was actually triggered.
 

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