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
Solved

subform sourceobject

Posted on 2014-04-10
8
463 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
  • 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 49

Accepted Solution

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

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

/gustav
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

828 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