Results 1 to 10 of 10
  1. #1
    varadin is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Posts
    10

    Passing data from selected record on form to subreport

    I currently have a button that I click that will open a report and pass the current record to the report. See below:



    Code:
    Private Sub cmdPrint_Click()
        Dim strWhere As String
    
        If Me.Dirty Then    'Save any edits.
            Me.Dirty = False
        End If
    
        If Me.NewRecord Then 'Check there is a record to print
            MsgBox "Select a record to print"
        Else
            strWhere = "[ID] = " & Me.[ID]
            DoCmd.OpenReport "CoC1", acViewPreview, , strWhere
        End If
    End Sub
    I have the need to print full page graphics in the report though that are displayed through an ActiveX control that is dropped on the report. In order to do this and stay within the 22" requirement of a report, I have decided to use subreports. (Help me if I'm wrong).

    The issue I am having is, how do I pass the values of the current record on button press to not only the main report, but also the subreports. I tried cheating and adding lines the the above code such as:

    Code:
            DoCmd.OpenReport "Picture1", acViewPreview, , , acHidden, strWhere
    But that obviously didn't work.

    Can anyone give me some insight as to how I would be able to pull the selected record via button push and pass that data to multiple subreport inside of the main.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,919
    Only the main report can be 'Opened', subreports just tag along. You are not passing the record, you are passing criteria to filter the report's RecordSource. If there is a Master/Child relationship then the subreport records will synchronize to the main report.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    varadin is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Posts
    10
    Relationship - I'm going to run with that keyword and see what I can work out. Thanks June - I will report back with findings.

  4. #4
    varadin is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Posts
    10
    I am unable to find where I can modify relationships for reports. Tables, forms, etc... I can see - but not reports. I went through the property sheets for the master and the subreports as well and did not see anything either.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,919
    What do you mean by 'modify relationships' of tables and forms? I am not suggesting you modify any relationships but take advantage of them. Master/Child links are properties of the subform/report container control. If there is a relationship between the data of the main and subreport by a common key field, then links can be set in the Master/Child link properties.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    varadin is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Posts
    10
    Master/Child link properties? I don't mean to sound completely obtuse, but can you point me in the right direction just so I can get on the right track?

    Is there a setting to make a subrecord "child" of the master.

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,919
    If you have a subform or a subreport then there is a container control on the main form/report that 'holds' the related data. The container has a SourceObject property. SourceObject can be a table, query, form, report. The container control also has Master/Child link properties. In design view click the edge of the subreport. Should see a narrow orange outline appear. The container control is selected. Click within the outline to select the SourceObject. Review Access Help for detailed guidance. This is basic Access functionality.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    varadin is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Posts
    10
    I see what you are talking about - but I'm looking to just pull the data from the selected record on my form to the subreport. Right now I have it of course set to pull from the table that the information is stored in - so it ends up generating multiple pages of data (one for each record).

    If I were to somehow filter the data, how would I tell it what record ID to pull?

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,919
    As I said, you don't 'pass' or 'pull' a record from form to report, you pass criteria. You already do that. Is the subreport in Single or Datasheet view? Do the main and sub have a key relationship? One-to-One, One-to-Many?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    varadin is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Posts
    10
    After making you pull your hair out trying to get me to understand... I figured out a way to do it using queries. =) I am going to have to modify this database heavily when I'm finished, as I understand relationships a bit more now.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 03-31-2011, 12:18 PM
  2. Passing Data from on Form to Another..
    By ETCallHome in forum Forms
    Replies: 2
    Last Post: 03-12-2011, 12:26 AM
  3. Replies: 1
    Last Post: 10-13-2010, 12:40 PM
  4. Form not passing data to query
    By bobfin in forum Queries
    Replies: 13
    Last Post: 08-11-2010, 05:28 AM
  5. Loading the form with selected record
    By emilylu3 in forum Access
    Replies: 1
    Last Post: 12-09-2005, 07:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums