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

599 Views Asked by At

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?

1

There are 1 best solutions below

0
Parfait On BEST ANSWER

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