Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    camftm is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2010
    Posts
    5

    Pass Subform filter to subform in report

    Hi,

    I cant seem to figure out how to pass a filter from a subform to a subform in my report so I can open the report in print preview to print.

    I have a Main form (Summary) that includes a subform (SummaryQuerySubfrm) which are linked together by ID.

    I have a combo box on the main form which filters the subform by using the code below in the after update event of the combo box.

    Private Sub SummaryMonth_AfterUpdate()
    SummaryQuerySubfrm.Form.Filter = "[SubformField]= '" & ComboBox & "'"


    SummaryQuerySubfrm.Form.FilterOn = True
    End Sub

    I want to be able to print the current main form and the filtered subform the user has selected via a report (Print preview).

    I am not sure how to pass the filter from my subform on my main form to the subform on my report.

    At the moment when I select the print button on my main form, it brings up the print preview of the report however it does not filter the subform within the report.

    I have been searching the forums but cant seem to find an answer. I have been stuck on this part of my database for ages, any help would be greatly appreciated.

    Thanks

    Ross

  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
    This is an untested shot in the dark, but you could try similar code in the load event of the subreport that sets the subreport filter equal to the subform's filter (either using the same type filter text or simply referring to the subform's filter property).
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    camftm is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2010
    Posts
    5
    I am not sure how the syntax would work with that. On my report I have put a subform on there instead of a subreport because it is displayed better, is that not good?

    Would the syntax on the on open event of my subform in the report be along the lines of

    Private Sub Form_Open(Cancel As Integer)

    SummaryQuerySubfrmReport.Report.Filter = "[SubformReportField]= '" & Forms!Summary.ComboBox & "'"
    SummaryQuerySubfrmReport.Form.FilterOn = True

    End Sub

    I am very new to access and have not really done much VBA so my coding is very novice.

    Any help would be great.

    Thanks

  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
    To be honest I've never mixed forms and reports like that. I would assume that you'd have to use "Form" instead of "Report" here:

    SummaryQuerySubfrmReport.Report.Filter = "[SubformReportField]= '" & Forms!Summary.ComboBox & "'"

    But since the code is running in the load event of that subform, you should be able to use:

    Me.Filter = ...
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    camftm is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2010
    Posts
    5
    Thanks for the info.

    I have tried the below code in the on open event of the subform in my report.

    Me.Filter = "[Expr1]= '" & Forms!Summary.ComboBox & "'"
    Me.FilterOn = True

    When I try and open my form I get a Run-time error 2465 Application-defined or object-defined error.

    When I try and debug the error it seems to be pointing to me not referencing the field that filters the subform. "Microsoft Office Access can't find the field '|' referred to in your expression You may have misspelled the field name, or the field may have been renamed or deleted."

    Does this reference seem correct? Forms!Summary.ComboBox (This should be a reference to the combobox on my main form that intialy filters the subform.

  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,521
    Have you tried the load event as I suggested? I don't believe the data is available yet in the open event.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    camftm is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2010
    Posts
    5
    Tried it in the On Load event and the same error.

    Can you think of anything else to try?

  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,521
    Can you post the db?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    camftm is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2010
    Posts
    5
    Hi,

    I have attached my database. I have stripped out all the unnecessay forms and queries from it.

    If you open the summary form you can filter the subform by the month combo box on the main form. When you select the print button it does not carry over the filter to the subform in my report.

    Any help would be great.

    Thanks

  10. #10
    dinorbaccess is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2010
    Posts
    27
    thats also my problem buddy. Did you get it to solve this problem.

    If yes, please tell me how. I have the exactly same problem

  11. #11
    Callahan is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    25
    I am having a similar problem with Access 2010. Using Access 2003, I could use a form filter in a report. With Access 2010, this does not work, and I cannot find a fix.

  12. #12
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Have you tried copying the filter from the suform to the subreport?
    I never use filters for this kind of thing I always use queries but I would think you could do something like:

    ReportName.filter = form.subform.filter

    Again, I'm not sure of the exact syntax for referencing the subform this way but the concept is sound. I would imagine you would have to put it in the ON OPEN event of the report for it to work.

  13. #13
    Callahan is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    25

    Reply to rpear

    Thanks for the reply.

    Yes I've tried using the on open report to no avail, I've tried every thing I can think of every which way but loose, all to no avail. I've pasted the filter into the filter box in the Report Properties, and sometimes it will filter the way it should, but most of the time it ignores the filter. Somthing is wrong with this Access 2010 report writer, in my humble opinion.

  14. #14
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Code:
    Dim sFilter As String
    sFilter = Me.Filter
    
    DoCmd.OpenReport "Rpt_testfilter", acViewDesign
    Reports!rpt_testfilter.Filter = sFilter
    Reports!rpt_testfilter.FilterOn = True
    DoCmd.OpenReport "Rpt_testfilter", acViewPreview
    This is what I ran. I gave my form a filter that worked then passed the filter and turned the filter on the report. I based both the form and the report on the same data as well (obviously) and it worked.

  15. #15
    Callahan is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    25

    close, no cigar

    Tried that and got a quick glance at correct report with filtering in place, a short pause and the report preview re-displays without filtering.

    Could be that because I'm trying to use a complex database developed with 2003 Access in the 2010 environment, the Access god's are against me. Maybe, I'll have to painfully rebuild the database one little bit at a time? I'm going to give that theory a shot.

    Thanks rpeare.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Access Reports - Applying a subform filter
    By AMCUser in forum Queries
    Replies: 13
    Last Post: 06-25-2010, 07:32 PM
  2. how to pass pk to subform
    By ahmed.gomaa in forum Forms
    Replies: 9
    Last Post: 03-21-2010, 10:03 AM
  3. Replies: 7
    Last Post: 05-24-2009, 10:24 AM
  4. Replies: 1
    Last Post: 03-01-2009, 09:53 AM
  5. command button to filter a subform issue -
    By countdrako in forum Forms
    Replies: 1
    Last Post: 12-09-2005, 11:58 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