Search code examples
vbams-accesswith-statementsubreports

MS Access VBA Referring to controls on a sub report using 'with'


Using MS Access VBA the following code works for me:

Reports.PARENT_REPORT_NAME.CHILD_REPORT_NAME.Report.Label1.Caption = "Yes"

However this does not:

With Reports(PARENT_REPORT_NAME)
.CHILD_REPORT_NAME.Report.Label1.Caption = "Yes"

Does anyone have any insight for me please?


Solution

  • Consider the Reports collection and Report.Controls property which allow string references of object names:

    With Reports("PARENT_REPORT_NAME")                
       .Controls("CHILD_REPORT_NAME").Report.Label1.Caption = "Yes"
       ...
    End With