Posted on 2014-04-10
I am attempting to open a form then change the sourceobject of the subform. Here is my code:
Private Sub btnEditRpt_Click()
Dim formname As String
Dim formfilter As String
formname = [Forms]![frmReport]![frmReportReportList_Sub].[Form]![TemplateName]
formfilter = "[autoReportsAll] = " & [autoReportsAll]
DoCmd.OpenForm formname, , , [formfilter]
Forms![xtemplate1]![MainReportForm].SourceObject = [ReportName]
The form opens and filters fine, however, in the line that changes the SourceObject I would like to substitute "xtemplate1" (which is an actual form name) with a form name residing in a form field called "TemplateName". (as I did to open the form) .
I have two fields in the form/subform where this code executes from a button: TemplateName and ReportName.
MainReportForm is the name of the subform object.
Help is appreciated.