Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Control arrays in Access? (As in VB)

Status
Not open for further replies.

ViPeRSe7eN

Programmer
Feb 6, 2003
5
AU
I have a form with 32 labels, 32 combo boxes with slightly different sql querys each, and 32 buttons. I know access doesnt support control arrays, but i cant see any other way of doing it without individually naming each control and pasting in 96 instances of code then changing the names. which i dont wanna do.

cant i create the controls dynamically in vba as an array? i know a decent amount about vb and vba, but have never played with dynamic controls. would this work? and if so how would i do it?

Ive got a hack going at the moment for the labels and combo boxes which basically consists of :

dim labelarray(0 to 40) as label

labelarray(0) = label1
labelarray(1) = label2
labelarray(2) = label3
labelarray(3) = label4
labelarray(4) = label5
labelarray(5) = label6
.... and so on

but i cant do this for the command button, im working on a hack for it now (just 1 line of code in each button that passes a number to another sub)
private sub cmdclick(clickindex)
' do stuff
end sub
private sub cmd1_click()
cmdclick(1)
end sub
private sub cmd2_click()
cmdclick(2)
end sub
... and so on

but this is all messy, and makes it hard to make changes later, there has to be a better way.
 
this is what i do for command buttons on mt touch screen keypad i create a function and the on click is
=functionname() and in the code i know whice command button i click with the me.activecontrol.caption
for lables and textboxes
i name them lable1,lable2....
and i run this for next statement
for co = 1 to xxxx
me.("lable" & co)
'the first time it is equle to lable1 the 2nd to lable2 and so on
next co
 
Hallo,

Like pwise says, create all your controls in design view and rename them with a number at the end. This works fine, although I think you have to refer to them as:
Code:
me("lable" & co).Caption = "Text " & co
(using pwise's example)

- Frink
 
Actual, Frink.. the way to refer to controls with variable that I use is:
Code:
Me.Controls("lable" & co).Caption = Text " & co

It's always worked for me, and when you debug to code (or someone else does) they know what you are refering to easier.

GComyn
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top