I have a Form with a Frame control array. Within each Frame are a number of other Controls, about 20 of them, which are also Control Arrays.
When loading a new Control within a given Frame, rather than type out 20 'Load' and other positioning statements etc., I thought of using a For / Next loop iterating thought the Controls collection of the Form. Here is the 'proof of concept':
Basically I have Frame(0) drawn of the Form and within that I have drawn the Text(0) and Label(0) Controls. On clicking Command it's meant to load elements Text(1) and Label(1).Code:Option Explicit Private Sub Command_Click() Dim ctl As Control Load Frame(1) Frame(1).Visible = True Frame(1).Top = Frame(0).Top + Frame(0).Height For Each ctl In Me.Controls If ctl.Container.Name = Frame(0).Name Then Load ctl(1) Set ctl(1).Container = Frame(1) ctl(1).Top = ctl(0).Top ctl(1).Left = ctl(0).Left ctl.Visible = True End If Next End Sub Private Sub Form_Load() Set Text(0).Container = Frame(0) Set Label(0).Container = Frame(0) End Sub
The Frame loads fine but when it comes to loading the TextBox and Label I get an error: 344 "Must specify index for object array"
I've messed around with the Load statement but nothing I've tried has worked (yet)
Am I doing something incredibly stupid or is this one of those things that 'can't be done' like this ? (similar to trying to Unload a Control in an Click Event procedure) If so does anyone know of an alternative method?




Reply With Quote