I am designing a wizard that enables the user to select a series of fields to place on a custom table. The selected fields are stored in tblSelectedFields in the order that the user selects. Their pre-determined properties (i.e. control size, control type, control name, etc) are stored in tblAvailableFields. The custom form template is frmCustomTakeoff with a record source of qryCreateForm.
I am trying to create a For Each...Next loop to cylce through the selected fields and place them on frmCustomTakeoff. I don't seem to understand how to properly address the element and the group.
I want the loop to execute as long as there is a field left in my query. I think that FieldName is my element and that qryCreateForm is by group. Is this correct? If so, what is the proper syntax to set up my loop. If this is not correct, what am I missing?
Here is my code:
Private Sub cmdDetailsNext_Click()
Dim frm As Form
Dim ctlLabel As control, ctlControl As control, ctlName As Variant
Dim intLabelX As Integer, intLabelY As Integer
Dim intDataX As Integer, intDataY As Integer
Dim intTabIndex As Integer
' Set project name value
ProjectName = Forms!frmDetails!txtProjectName
'Open "frmCustomForm" form in design view
DoCmd.OpenForm "frmCustomTakeoff", acDesign
' Set positioning values for new controls
intTabIndex = 0
intLabelX = 100
intLabelY = 100
intDataX = 1000
intDataY = 100
For Each ctlName In qryCreateForm
ctlName = [qryCreateForm]![FieldTitle]
Set ctlControl = CreateControl("frmCustomTakeoff", [qryCreateForm]![FieldType], , "", "", intDataX, intDataY)
'Create child label control for text box
Set ctlLabel = CreateControl("frmCustomTakeoff", acLabel, , ctlControl.Name, "New Label", intLabelX, intLabelY)
'Restore from
DoCmd.Restore
Next
End Sub
Thanks in advance.
Scott
I am trying to create a For Each...Next loop to cylce through the selected fields and place them on frmCustomTakeoff. I don't seem to understand how to properly address the element and the group.
I want the loop to execute as long as there is a field left in my query. I think that FieldName is my element and that qryCreateForm is by group. Is this correct? If so, what is the proper syntax to set up my loop. If this is not correct, what am I missing?
Here is my code:
Private Sub cmdDetailsNext_Click()
Dim frm As Form
Dim ctlLabel As control, ctlControl As control, ctlName As Variant
Dim intLabelX As Integer, intLabelY As Integer
Dim intDataX As Integer, intDataY As Integer
Dim intTabIndex As Integer
' Set project name value
ProjectName = Forms!frmDetails!txtProjectName
'Open "frmCustomForm" form in design view
DoCmd.OpenForm "frmCustomTakeoff", acDesign
' Set positioning values for new controls
intTabIndex = 0
intLabelX = 100
intLabelY = 100
intDataX = 1000
intDataY = 100
For Each ctlName In qryCreateForm
ctlName = [qryCreateForm]![FieldTitle]
Set ctlControl = CreateControl("frmCustomTakeoff", [qryCreateForm]![FieldType], , "", "", intDataX, intDataY)
'Create child label control for text box
Set ctlLabel = CreateControl("frmCustomTakeoff", acLabel, , ctlControl.Name, "New Label", intLabelX, intLabelY)
'Restore from
DoCmd.Restore
Next
End Sub
Thanks in advance.
Scott