Copying control in code

  • Thread starter Thread starter Sheldon
  • Start date Start date
S

Sheldon

In pure VB I can place an object on a form, give it an
index, and then in code copy it, and place it where I
want. Such as

Dim i As Integer

For i = 1 To 5
Load txtAnswers(i)
txtAnswers(i).Top = txtAnswers(i -).Top
+ txtAnswers(i - 1).Height + 100
txtAnswers(i).Visible = True
Next i

This is particularily useful when you don't know how many
copies of the control you need until run time.

I cannot find an index property for a control. How can I
accomplish this in Access VBA code
 
Access VBA has no control arrays, unlike VB. You can simulate a control
array, by manipulating name strings, like txt1, txt2 etc. But the real
limitation is that you can only create around 750 controls on a form *over
its entire life*. So if you add a few controls at each execution, you will
quickly exceed this limit. Destroying them does not reduce the count.
In Access, the only way appears to be to set up a fixed number of controls,
larger than you will ever need, then turn the visible property on and off as
you need.

--
Regards,

Adrian Jansen
J & K MicroSystems
Microcomputer solutions for industrial control
 
When you do what you describe in VB, you are using a "Control Array". Access
and VBA do not support Control Arrays. In Access, you create as many
controls as you may need, and just set the Visible property to Yes for all
that you _do_ need. Quite often, Control Arrays are used in VB where a
Subform Control with a Form in Continuous Forms View would be used in Access
(not always, though, but it's worth considering whether that would serve the
same purpose).

Larry Linson
Microsoft Access MVP
 
Back
Top