cwbarrett
asked on
subform sourceobject
Hi,
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]![frmRe portReport List_Sub]. [Form]![Te mplateName ]
formfilter = "[autoReportsAll] = " & [autoReportsAll]
DoCmd.OpenForm formname, , , [formfilter]
'
Forms![xtemplate1]![MainRe portForm]. SourceObje ct = [ReportName]
End Sub
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) .
Notes:
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.
Charlie
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]![frmRe
formfilter = "[autoReportsAll] = " & [autoReportsAll]
DoCmd.OpenForm formname, , , [formfilter]
'
Forms![xtemplate1]![MainRe
End Sub
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) .
Notes:
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.
Charlie
Try this
me![MainReportForm].Source Object = [TemplateName]
me![MainReportForm].Source
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
:-0
ASKER
Tried a few different things. Still can't do it. Here is the modified code. The form opens but getting an error "cannot find the referenced form 'formTemplateName'" and debugging shows the last line as the culprit. What am I doing wrong?
Private Sub btnEditRpt_Click()
Dim formTemplateName As String
Dim formfilter As String
Dim subformSourceObject As String
formTemplateName = [Forms]![frmReport]![frmRe portReport List_Sub]. [Form]![Te mplateName ]
formfilter = "[autoReportsAll] = " & [autoReportsAll]
subformSourceObject = [Forms]![frmReport]![frmRe portReport List_Sub]. [Form]![Re portName]
DoCmd.OpenForm formTemplateName, , , [formfilter]
Forms![formTemplateName]![ MainReport Form].Sour ceObject = [subformSourceObject]
End Sub
Private Sub btnEditRpt_Click()
Dim formTemplateName As String
Dim formfilter As String
Dim subformSourceObject As String
formTemplateName = [Forms]![frmReport]![frmRe
formfilter = "[autoReportsAll] = " & [autoReportsAll]
subformSourceObject = [Forms]![frmReport]![frmRe
DoCmd.OpenForm formTemplateName, , , [formfilter]
Forms![formTemplateName]![
End Sub
ASKER
Why does formTemplateName work to open the form (DoCmd.OpenForm formTemplateName, , , [formfilter]) but doesn't work when referencing it to set the SourceObject?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you. You both were a great help.
Forms![xtemplate1]![MainRe
maybe this is wht you are looking for
Forms(formName)("MainRepor