Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Reports Subreports and Specific Filtering
Jasen Hicks 
     
16 months ago
Good Morning! I spent the better part of the day trying to figure this out using Google, but nothing has yielded proper results.

Background:

1. I am cataloging Journalists, Articles they write, etc.
2. I store all my journalist information in one table, all the news article data in another. There is a one to many relationship between journalists and news articles by joining on idJournalist; this is the PK in the journalist table and a column in the article table.
3. News articles have additional tagging, so let's call that additional tag "focus"
4. I have a main report that pulls from the Journalist Table. I have a couple sub reports, linked via the idJournalist fields.

Running this report gives me everything it works great. All the journalist information at the top, then the subreports have all the articles they ever wrote and I have cataloged, their social media information (stored in another table to simiplify and maximize growth potential), and another sub report that has some of my thoughts about the article.

What I need to do is customize the report and tailor each of these sections. Examples:

1. I want all the articles related this focus area
2. Limit to this date range.
2. I want this specific journalist.
3. A combination of the above.

I created a form to capture my refining options, the journalist selection is passed as as a WHERE condition in the DoCmd.OpenReport line in my form and in the OnOpen event for the article sub report I used:

[code]
Private Sub Report_Open(Cancel As Integer)
    
    Dim SQL
    SQL = Forms!ReportGenerator_F!SQL4

    If Not IsNull(SQL) Then
        Me.RecordSource = "SELECT * FROM MediaArticleList_ForReports WHERE " & SQL
    End If
End Sub
[/code]

I build the WHERE statement in the form and pass it along to the subreport. But I am getting the Runtime error 2191: You cant sent the record source property in print preview or after printing has started.




Jasen Hicks OP  @Reply  
     
16 months ago
Code from my Form that has my filter criteria:

DetailsPrivate Sub GenerateReport_BTN_Click()

    Dim SQL As String, WhereStr As String, SubReportWhereStr
    
    WhereStr = ""
    SubReportWhereStr = ""
    
    If jounalist_search <> "" Then
        WhereStr = "idJournalist=" & jounalist_search & ""
    End If
        
    If client_search <> "" Then
        If SubReportWhereStr <> "" Then SubReportWhereStr = SubReportWhereStr & " AND "
        SubReportWhereStr = SubReportWhereStr & "idClient=" & client_search & ""
    End If
      
    If net_search <> "" Then
        If SubReportWhereStr <> "" Then SubReportWhereStr = SubReportWhereStr & " AND "
        SubReportWhereStr = SubReportWhereStr & "articleDate > #" & (net_search - 1) & "#"
    End If
    
    If nlt_search <> "" Then
        If SubReportWhereStr <> "" Then SubReportWhereStr = SubReportWhereStr & " AND "
        SubReportWhereStr = SubReportWhereStr & "articleDate < #" & (net_search + 1) & "#"
    End If
      
  
    ' SQL = "SELECT * FROM JournalistProfileQ"
    
    If WhereStr <> "" Then
    
        SQL = WhereStr
    
    End If
    
    If SubReportWhereStr <> "" Then
        SQL3 = SubReportWhereStr
    End If
        
    SQL2 = SQL
    SQL4 = SQL3
    
    DoCmd.OpenReport "JournalistR", acViewPreview, , SQL, , SQL3
    
    

End Sub
Kevin Robertson  @Reply  
          
16 months ago
Try setting the RecordSource of the Report in the button on the Form that opens the Report.

    DoCmd.OpenReport has a WhereCondition argument
Jasen Hicks OP  @Reply  
     
16 months ago
Kevin, I do have a where condition set on the JournalistR (the main report) set in my VB code, that's the "SQL" variable being sent. The main report though only shares one common field with the subReports, and that's idJournalist. I first made the WHERE condition so it passed all the thing I hoped to filter on the subreports, but it didn't' work. It popped up the access question boxes like it was missing something.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 6/17/2026 11:22:40 AM. PLT: 0s