Creating controls on the fly
Posted on 2011-03-25
I have a couple of questions about creating controls at runtime.
My logic is this:
1. Create a new form
2. on new form create new controls (combo)
3. the code for creating these controls is within a loop
4. set the recordset of the controls for each control during each pass of the loop
So far I managed to do steps 1,2,3. However I cannot set up the recordset.
Here is the code I have:
' Create new form with Orders table as its record source.
Set frm = CreateForm
' Set positioning values for new controls.
intLabelX = 100
intLabelY = 100
intDataX = 1000
intDataY = 100
For intCounter = 1 To 10
' Create unbound default-size text box in detail section.
Set ctlText = CreateControl(frm.Name, acComboBox, , "", "", _
ctlText.Name = intCounter
intDataY = intDataY + 400
ctlText.Recordset = GetADORecordset("SELECT receipt_number, running_qty, identifier, order_number FROM " & _
' Create child label control for text box.
Set ctlLabel = CreateControl(frm.Name, acLabel, , _
ctlText.Name, "NewLabel", intLabelX, intLabelY)
intLabelY = intLabelY + 400
1. What is best way to set up the recordset of each of the controls
2. Can the form name be sepcififed (defaults to Form1, Form2, etc…) I’ve tried frm.name = “new name” however it gives a read only message.