-
Say I have an undetermined amount of records returned from a query.I want to create textboxes, checkboxes, etc. on the fly for the correct number of records. Is there a way to place controls on a form at runtime without having to pile a buch of invisible ones on form and then making them visible. The result would be like the data repeater control, but I only have the option of DAO. I think the data repeater only works with ADO.
-
Use an object array and a code similar to this:
Code:
-------------------------------------------------------
¡® Create a control, say a textbox, in advance and set the index as 0
¡® rs is your recordset
¡® 300 is the vertical space as you wish between textboxes
Dim intNumOfRecord As Integer
Dim i As Integer
intNumOfRecord = rs.RecordCount
For i = 1 To (intNumOfRecord ¨C 1)
Load Text1(i)
With Text1(i)
.Top = Text1(i - 1).Top + 300
.Visible = True
End With
Next
For i = 0 To (intNumOfRecord ¨C 1)
Text1(i).Text = rs.Fields(0)
rs.MoveNext
Next
------------------------------------------------------
Hope it helps.
-
I like it
This is clever. Thanks a bundle, I thought I was going to have to put a bunch of invisible text controls on the form.
Can I do this with any control?
-
I am glad you like it.
I think you can do that with many, if not any, controls, such as command controls, picture boxes, labels, etc.