Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    alexandervj is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    145

    How to print report based on what user is looking at


    I have a form/subform with the subform as a continuous form that looks like a spreadsheet. I want a way for the user to hit a 'Print Report' button after selecting various filters in the subform and it builds a report based on the filters selected. Is this possible? How would I go about this? Thanks

  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 might work:

    DoCmd.OpenReport "ReportName", acViewPreview, , Forms!FormName.SubformName.Form.Filter
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    alexandervj is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    145
    Thanks pbaldy! Seems to partially work - it opens the report for whats filtered in the subform but looks like its for multiple IDs in the form. So it opens up a report showing 2 groups, 1 group is the one I'm looking at in the form, then another group looks almost random. Is there a way to add a where to this? Like 'where ParentID=[ParentID_FK]?'

  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
    Oh, it probably isn't considering anything in the master/child links. How about:

    DoCmd.OpenReport "ReportName", acViewPreview, , Forms!FormName.SubformName.Form.Filter & " AND ParentID = " & Me.ParentID

    adjusting for your names of course.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    alexandervj is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    145
    trying to do something like this, although syntax is off im sure

    DoCmd.OpenReport "rpt_Parts", acViewPreview, , [LotID]= Me.LotID_FK And [RunID]= Me.RunID_FK And Forms!frm_Parts_Datasheet.frm_Parts_Spreadsheet.Fo rm.Filter

    So that it filters based on two "where ID=ID_FK" 's and also the part you gave me at the end. Thanks!

  6. #6
    alexandervj is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    145
    Awesome! That worked for adding 1 where clause, if I wanted to add 1 more would it look like...

    DoCmd.OpenReport "ReportName", acViewPreview, , Forms!FormName.SubformName.Form.Filter & " AND ParentID = " & Me.ParentID " AND ParentID = " & Me.ParentID

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Close; you missed an &.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    alexandervj is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    145
    Aha, how about this...

    DoCmd.OpenReport "ReportName", acViewPreview, , Forms!FormName.SubformName.Form.Filter & " AND Parent1ID = " & Me.Parent1ID & " AND Parent2ID = " & Me.Parent2ID


    Thanks again

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

  10. #10
    alexandervj is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    145
    Works great! And one more question - this keeps the same filters as in the report, is there a way to keep the same sort as well?

  11. #11
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Are they doing their own filtering/sorting via built-in methods? I always control it all, so in my case they would make their selections and I would read the sorting selections in the open event of the report and apply them. I'm not sure how to do it with the user doing it on their own. You can test the Order By property of the form, but I'm not sure how to apply that to Sorting and Grouping on the report.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  12. #12
    alexandervj is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    145
    yeah, theyre doing their own sorting/filtering via built in methods. Its ok no worries...
    On another note: I am also trying to open an identical form but with only parts with deleted field = true or in the "reject/trash" location. So should have the same WHERE statement but with those 2 conditions added. I tried this...
    DoCmd.OpenReport "rpt_Parts_Inactive", acViewPreview, , Forms!frm_Parts_Datasheet.frm_Parts_Spreadsheet.Fo rm.Filter & " AND LotID = " & Me.LotID & " AND RunID = " & Me.RunID & " AND Deleted = True OR GeographicalLocation = 'Reject/Trash'"
    but that obviously gives parts according to all the AND statments as well as parts in the OR statement, so it will return all parts in the reject/trash, even if they dont have the right LotID, and RunID,...
    how can I group those last 2 statements? The AND Deleted = True OR GeographicalLocation = 'Reject/Trash'"

    Thanks again!

  13. #13
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    How about:

    ...AND (Deleted = True OR GeographicalLocation = 'Reject/Trash')"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  14. #14
    alexandervj is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    145
    thats what I thought, but when I tried it nothing came up at all.. hmm..

  15. #15
    alexandervj is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    145
    Figured it out, forgot to change the form/subform name Thanks

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

Similar Threads

  1. Using VBA to print a report based off day of week
    By jo15765 in forum Programming
    Replies: 1
    Last Post: 10-21-2013, 02:10 PM
  2. Replies: 3
    Last Post: 03-11-2013, 05:11 PM
  3. Replies: 1
    Last Post: 01-24-2013, 12:52 AM
  4. Replies: 1
    Last Post: 12-09-2012, 05:27 PM
  5. Need Help Creating Report Based on User Entry
    By italianfinancier in forum Programming
    Replies: 17
    Last Post: 05-27-2011, 04:58 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