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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamically adding indexed controls in a frame

Status
Not open for further replies.

rjmccorkle

Programmer
Aug 26, 2000
55
US
I am trying to write code to duplicate a frame and it's controls at runtime. I can do it using the LOAD command and the individual control names. I would like to use a loop through the template frame's controls so I don't have to remember to add new code if I add a new control to the frame. To make it easier in the looping, I have every control in the template frame as an array with index 0 (so far about 50 controls; labels,textboxes,comboboxes,optionbuttons,frames). Here is the bit of code I am trying to use

vC=UBound(fraP)+1
For Each ctl In Controls
If Not ctl.Name Like "tim*" Then
If ctl.Container Is fraP(0) Then
Load ctl(vC)
End If
End If
Next ctl

1.Is there a way to address just the controls in the frame? Research so far shows I have to go through the form's controls then test the control's container (and I found out by experience that apparently Timer controls don't have Containers) and since I have frames inside the template frame, I will have to add the sub-frames' controls, perhaps using a subroutine called recursively.
2.The LOAD ctl(vC) generates a 344 Error. The ctl variable is referencing the indexed control like txtT(0), not the (my vocabulary is weak here) array txtT. How do I pass the Index for the new control?
Thanks for any help.
Bob
 
Thanks for the reply John (and your previous posts where I found out about the UBound function). That generates a Type Mismatch in the UBound function because the ctl variable is referring to control(0) rather than the array control. That's the problem I have not been able to find a solution for.
Bob
 
I think I found an answer to my 2nd question:
me.Controls(ctl.Name)
refers to the array so I tried something like this:
Dim ctl, ctl2, vC as Integer
vC=UBound(fraP)
Load frap(vC)
For Each ctl in Controls
if ctl.Container Is fraP(0) then
set ctl2=me.Controls(ctl.Name)
load ctl2(vC)
set ctl2(vc).Container=fraP(vc)
end if
Next ctl

Then I set the top, left & visible properties. The "SET" for the new controls Container took me a bit to figure out. Without the SET, no errors occur but nothing shows up.

So, does anyone know how to reference the controls in a frame without going through all of the Form's controls?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top