A
Amy Blankenship
I am working with a Form with a subform. The parent form refers to a query
that selects all AuditToolGroups from my AuditToolGroup table which don't
have a parent ID. This is because the AuditToolGroup table is
self-referencing and can be its own child. Therefore, there's another
subform based on the same table, but returning all AuditToolGroups that DO
have a ParentID.
When an AuditToolGroup does not have another AuditToolGroup as a child, it
will have Fields as children. Therefore, there is a second subform,
AuditToolField, which can live in the AuditToolGroup Subform control or can
live in its own control within the AuditToolGroup Subform.
I had all this working fine, but then the next time I opened the database,
it asked me for a parameter [AuditToolGroup]. So I did a little Googling
and changed the queries so that the LinkChildFields is always AuditToolGroup
and the LinkMasterFields is always AuditGroupID.
So ParentID is aliased to AuditToolGroup in the child query of the
AuditToolGroup Subform, and AuditGroupID is always the primary key for the
AuditToolGroup at the particular level of the firm structure.
All this works fine when the AuditToolGroup has no AuditToolGroup children,
and the Fields are directly nested within the main form. However, when the
AuditToolFields is nested in the AuditToolGroup subform, it incorrectly
links to the AuditGroupID of the main form. I can look at the form and SEE
that the AuditGroupID in the AuditToolGroup subform is correctly set, but
the AuditToolFields AuditToolGroup shows as the same as the main form, not
its own parent form.
The code that switches out the subforms is very simple:
Private Sub Form_Current()
Me![AuditToolChildGroups Subform_Label].Caption = "Sub Group"
With Me![AuditToolChildGroups Subform]
.SourceObject = "AuditToolChildGroups Subform"
Debug.Print .Form.RecordsetClone.RecordCount
Debug.Print .SourceObject
If .Form.RecordsetClone.RecordCount = 0 Then
.SourceObject = "AuditToolField subform"
Debug.Print .SourceObject
Me![AuditToolChildGroups Subform_Label].Caption = "Fields"
End If
End With
End Sub
Am I missing something about how this is supposed to work?
TIA;
Amy
that selects all AuditToolGroups from my AuditToolGroup table which don't
have a parent ID. This is because the AuditToolGroup table is
self-referencing and can be its own child. Therefore, there's another
subform based on the same table, but returning all AuditToolGroups that DO
have a ParentID.
When an AuditToolGroup does not have another AuditToolGroup as a child, it
will have Fields as children. Therefore, there is a second subform,
AuditToolField, which can live in the AuditToolGroup Subform control or can
live in its own control within the AuditToolGroup Subform.
I had all this working fine, but then the next time I opened the database,
it asked me for a parameter [AuditToolGroup]. So I did a little Googling
and changed the queries so that the LinkChildFields is always AuditToolGroup
and the LinkMasterFields is always AuditGroupID.
So ParentID is aliased to AuditToolGroup in the child query of the
AuditToolGroup Subform, and AuditGroupID is always the primary key for the
AuditToolGroup at the particular level of the firm structure.
All this works fine when the AuditToolGroup has no AuditToolGroup children,
and the Fields are directly nested within the main form. However, when the
AuditToolFields is nested in the AuditToolGroup subform, it incorrectly
links to the AuditGroupID of the main form. I can look at the form and SEE
that the AuditGroupID in the AuditToolGroup subform is correctly set, but
the AuditToolFields AuditToolGroup shows as the same as the main form, not
its own parent form.
The code that switches out the subforms is very simple:
Private Sub Form_Current()
Me![AuditToolChildGroups Subform_Label].Caption = "Sub Group"
With Me![AuditToolChildGroups Subform]
.SourceObject = "AuditToolChildGroups Subform"
Debug.Print .Form.RecordsetClone.RecordCount
Debug.Print .SourceObject
If .Form.RecordsetClone.RecordCount = 0 Then
.SourceObject = "AuditToolField subform"
Debug.Print .SourceObject
Me![AuditToolChildGroups Subform_Label].Caption = "Fields"
End If
End With
End Sub
Am I missing something about how this is supposed to work?
TIA;
Amy