Results 1 to 2 of 2
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    1,919

    Filter fails when report used as subreport

    If I run the report "rptPerCapita-Sub" by itself with the following OnOpen code, the report opens filtered as expected.



    Code:
    Private Sub Report_Open(Cancel As Integer)
    Dim PDate As Date
    
    PDate = DLookup("[PerCapReportDate]", "tblSettings")
    
    Me.Filter = "(((DOPmt)>#" & PDate & "#) AND ((PCCode)='N')) OR (((DOPmt)>#" & PDate & "#) AND ((PCCode)='R'))"
    Me.FilterOn = True
    End Sub
    However, when I attempt to open a main report with "rptPerCapita-Sub" as a subreport, I get the error:
    Click image for larger version. 

Name:	001.jpg 
Views:	7 
Size:	25.8 KB 
ID:	24609
    And in Debug:
    Click image for larger version. 

Name:	002.jpg 
Views:	7 
Size:	51.5 KB 
ID:	24610

    Does the filter need to be set in the subreport container or something like that?

  2. #2
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    1,919
    One cannot filter a subreport. One either has to modify an existing query with a querydef OR set the RecrordSource in the Open event via a SQL "SELECT" expression.

    My solution:
    Code:
    Private Sub Report_Open(Cancel As Integer)
    Dim PDate As Date
    Dim strSQL As String
    
    PDate = DLookup("[PerCapReportDate]", "tblSettings")
    
    strSQL = "SELECT LastName, FirstName, DOPmt, PCCode, Address, City, State, ZIP, HomePhone, Fax, Cell, EMA FROM tblMembers" & _
             " WHERE (((DOPmt)>#" & PDate & "#) AND ((PCCode)='N')) OR (((DOPmt)>#" & PDate & "#) AND ((PCCode)='R'))" & _
             " ORDER BY LastName, FirstName;"
    Me.RecordSource = strSQL
             
    End Sub

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

Similar Threads

  1. Replies: 0
    Last Post: 02-25-2015, 08:09 AM
  2. subreport wont filter
    By gregst in forum Reports
    Replies: 1
    Last Post: 05-30-2013, 10:38 AM
  3. Replies: 1
    Last Post: 04-15-2013, 10:02 AM
  4. Replies: 3
    Last Post: 01-15-2012, 02:46 PM
  5. Report and Subreport
    By newbie in forum Reports
    Replies: 0
    Last Post: 02-16-2010, 12:14 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