skillilea
asked on
How do I loop though all fields including a sub form
I have a main form and a sub form:
fields on both
I am trying to loop through each field and keep getting error.
mainform = frmMain
subform = oSubFrm
The txtInnoScan throws the error.
fields on both
I am trying to loop through each field and keep getting error.
mainform = frmMain
subform = oSubFrm
The txtInnoScan throws the error.
Private Sub cmdAsset_Add_Click()
Dim controlArray() As Variant: controlArray = FormControls()
Dim ctl As Variant
For Each ctl In controlArray
MsgBox Controls(ctl).Name
Next
End Sub
Private Function FormControls() As Variant()
FormControls = Array("txtAssetType", "Forms!frmMain.txtInnoScan")
'"txtInnoScan",
End Function
I don't see the point of this code.
The only way it can display the name of a control is if you specify the name in advance in the array.
Can you describe what you are really trying to do and maybe someone will suggest a method.
The only way it can display the name of a control is if you specify the name in advance in the array.
Can you describe what you are really trying to do and maybe someone will suggest a method.
my response was to your first post.
ASKER
Sorry for the confusion.
I have 20 fields that are required prior a record entry.
I have an array of all the field names.
Some of these fields are on the parent or main form some are on a sub form.
I want to loop through each field and check for values but I can't seem to reference the mainform fields without two loops.
the code is being called from the sub form ie. the "Add New Button" is located on the sub form.
tnx for the help
I have 20 fields that are required prior a record entry.
I have an array of all the field names.
Some of these fields are on the parent or main form some are on a sub form.
I want to loop through each field and check for values but I can't seem to reference the mainform fields without two loops.
the code is being called from the sub form ie. the "Add New Button" is located on the sub form.
tnx for the help
Are you using bound forms? (Forms have a recordsource)
ASKER
nope...this is an unbound form
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
For Each ctl In Me.Parent.Controls
MsgBox ctl.Name Next
For Each ctl In Me.Controls
MsgBox ctl.Name
Next
how do I get all the controls on the page
tnx