Solved

subform sourceobject

Posted on 2014-04-10
8
465 Views
Last Modified: 2014-04-10
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]![frmReportReportList_Sub].[Form]![TemplateName]
    formfilter = "[autoReportsAll] = " & [autoReportsAll]
    DoCmd.OpenForm formname, , , [formfilter]
'
    Forms![xtemplate1]![MainReportForm].SourceObject = [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
0
Comment
Question by:cwbarrett
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39992036
if the name of the form you want to use is as source object is ReportName

Forms![xtemplate1]![MainReportForm].SourceObject = "ReportName"


maybe this is wht you are looking for

Forms(formName)("MainReportForm").SourceObject = "ReportName"
0
 
LVL 12

Expert Comment

by:pdebaets
ID: 39992205
Try this

me![MainReportForm].SourceObject = [TemplateName]
0
 
LVL 51

Accepted Solution

by:
Gustav Brock earned 250 total points
ID: 39992475
That would be:

   Forms(formName)("MainReportForm").SourceObject = [ReportName]

/gustav
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39992535
:-0
0
 

Author Comment

by:cwbarrett
ID: 39992659
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]![frmReportReportList_Sub].[Form]![TemplateName]
    formfilter = "[autoReportsAll] = " & [autoReportsAll]
    subformSourceObject = [Forms]![frmReport]![frmReportReportList_Sub].[Form]![ReportName]
   
    DoCmd.OpenForm formTemplateName, , , [formfilter]

    Forms![formTemplateName]![MainReportForm].SourceObject = [subformSourceObject]
   
End Sub
0
 

Author Comment

by:cwbarrett
ID: 39992679
Why does formTemplateName work to open the form (DoCmd.OpenForm formTemplateName, , , [formfilter])  but doesn't work when referencing it to set the SourceObject?
0
 
LVL 12

Assisted Solution

by:pdebaets
pdebaets earned 250 total points
ID: 39992891
Try this:

Forms([formTemplateName])![MainReportForm].SourceObject = [subformSourceObject]
0
 

Author Closing Comment

by:cwbarrett
ID: 39992950
Thank you.  You both were a great help.
0

Featured Post

10 Questions to Ask when Buying Backup Software

Choosing the right backup solution for your organization can be a daunting task. To make the selection process easier, ask solution providers these 10 key questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question