Results 1 to 9 of 9
  1. #1
    Berlioz is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2014
    Posts
    5

    Limiting records in a report after grouping

    Hello, sure glad to find this forum, I have been pulling my hair out trying to figure how to limit the number of records returned in the detail section of a grouped report.

    I have a report that has three grouping,
    .Track
    ..Surface
    ...Distance
    Then the actual records are sorted by descending date. This is where I want to limit the records to say the last 12. I can not filter on date because the last twelve could have happened anytime.

    I can not figure how to do it, please help.


    This is what I tried so far.
    I did a little research online and came across a forum that suggested the following
    -adding an invisible count box named counter, setting the control source property to =1 and setting the running sum box to across groups.
    This added a running count to the detail sections, it resets to zero at every new group.


    - then on Format event adding this code
    Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    If [Counter] >12 Then Cancel = True
    End Sub

    I get the count but the report still lists all records. I have never used VBA in the past, maybe I am missing something obvious. Hoping someone guides me in the right direction.

    Thank you in Advance

  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,652
    Untested, but if the count is right, try setting the visible property of the detail section to False (don't forget an Else clause setting it to True).
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Berlioz is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2014
    Posts
    5
    visible or not visible i have tried it both ways same result it still returns all records.

    and Else Clause ? I just copied the code from a forum, where would I add this ?
    I sorry to say I am not well versed in VBA, when it comes to this area I need baby instructions.

    Thank you


    Quote Originally Posted by pbaldy View Post
    Untested, but if the count is right, try setting the visible property of the detail section to False (don't forget an Else clause setting it to True).

  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,652
    In pseudo code:

    Code:
    if Whatever Then
      Visible = False
    Else
      Visible = True
    End If
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Berlioz is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2014
    Posts
    5

    Limiting in grouped report not just for printing

    Following the instructions, I was able to limit the number of records when sent to printer. However what i want to do is limit the amount of records in the report to the last 12 records. I have controls in the group header, I want these controls to only calculate the last 12 records.

    Or am I going about this all wrong, do I have a bigger design issue ?
    Any ideas ?


    Quote Originally Posted by pbaldy View Post
    In pseudo code:

    Code:
    if Whatever Then
      Visible = False
    Else
      Visible = True
    End If

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Have you looked at the TOP predicate in SQL? In other words, the query under the report would look like:

    SELECT TOP 12...
    FROM...
    WHERE...
    ORDER BY DateField DESC
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    Berlioz is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2014
    Posts
    5

    Top

    Using Top in the underlying query returned the top records across all records. I need a TOP records after they have been grouped.

    but thanks for the suggestion.


    Quote Originally Posted by pbaldy View Post
    Have you looked at the TOP predicate in SQL? In other words, the query under the report would look like:

    SELECT TOP 12...
    FROM...
    WHERE...
    ORDER BY DateField DESC

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    Berlioz is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2014
    Posts
    5

    looks promising

    Looks promising.... thank you for the great link.
    I'll try it out tomorrow and report back.

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

Similar Threads

  1. Replies: 5
    Last Post: 08-24-2013, 08:04 PM
  2. Question on database structure - limiting linked records
    By andrewb in forum Database Design
    Replies: 2
    Last Post: 03-22-2012, 05:41 PM
  3. Form limiting records
    By yaro.kobzar in forum Programming
    Replies: 1
    Last Post: 05-21-2011, 06:50 AM
  4. limiting amount of records
    By yaro.kobzar in forum Programming
    Replies: 1
    Last Post: 05-17-2011, 07:01 PM
  5. Limiting the results displayed in a report
    By musicalogist in forum Reports
    Replies: 1
    Last Post: 06-10-2010, 04:44 PM

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