Results 1 to 5 of 5
  1. #1
    EddieN1 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    May 2011
    Posts
    313

    How to modify sub report record source

    I have a main report with up to three sub reports depending on what check boxes the user selects on the form that calls the report. There is always a small amount of data on the main report. If the operator checks a check box for sub report 1, 2, or 3, then they appear as well. I have put the test for the check box in the sub report's underlying record source. However, this technique causes the sub report to open, read all the data from the record source query, and finally reject them all since the check box isn't checked. This works but makes the report run very slow. I would like to modify the record sources for the sub reports based on the check boxes before the sub reports open, so that if the check box for a sub report isn't checked, then the record source for the sub report is blank. What event should I use to modify the sub report's record source and what syntax should I use?

    Thanks, Eddie

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I'd start with the open event of the subreport. The code would look like:

    Me.RecordSource = "Whatever"

    Where Whatever is either an SQL string or the name of a saved query.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    EddieN1 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    May 2011
    Posts
    313
    pbaldy, Thanks for the response, however, that's not quite what I meant. I need to change the record source for the sub report dynamically. If the operator doesn't check the check box for that sub report, I want its record source to be changed to null. I think that when the main report opens, it should be able to do that, but under which event?

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I think I understood and would use the event mentioned. If the checkbox isn't checked, set it to a zls: ""
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    EddieN1 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    May 2011
    Posts
    313
    Okay, guys, I finally found out how to do this. First, the record source may be modified in the sub report's Open event. However, the trick is to do it only the first time through. Here's how...

    Static CallCount as integer
    If CallCount = zero then
    Me.RecordSource = "... whatever you want "
    Else CallCount = 1
    End If

    Thanks for eveyone's comments and suggestions.

    Eddie

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

Similar Threads

  1. Form Record Source - Best practices.
    By ser01 in forum Forms
    Replies: 1
    Last Post: 06-11-2011, 11:32 AM
  2. Resetting Record Source on Form
    By Cheshire101 in forum Programming
    Replies: 5
    Last Post: 05-05-2011, 08:52 AM
  3. Replies: 4
    Last Post: 12-16-2010, 12:45 PM
  4. Forms' Record Source
    By Progress2007 in forum Programming
    Replies: 11
    Last Post: 07-27-2009, 11:04 AM
  5. Changing the record source in a form
    By lmichaud in forum Forms
    Replies: 1
    Last Post: 07-09-2006, 09:20 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