Results 1 to 8 of 8
  1. #1
    Join Date
    Aug 2012
    Posts
    126

    Unanswered: Filtered results in a report

    Not sure the title explains what I need. I usually use a query and create a report off of that query and things work great. As my knowledge of access and vba broadens im seeing a whole new horizon on whats possible.

    My question:

    I have a report that has a column with three possible results (On premise, Off Premise, Both). I created a report that shows all three and I am wondering if I can tell the report to print only on premise both and then off premise both. I can easily do this in a query but I like to expand my knowledge

    Edit: I tried google and maybe my search criteria is wrong but all I see is how to show certain columns from a table/query...which i know how to do
    Last edited by Syrch; 10-01-12 at 17:31.

  2. #2
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    This would be one way, tweaking the criteria as appropriate:

    Open a second form to the record
    Paul

  3. #3
    Join Date
    Aug 2012
    Posts
    126
    thank you, I like this idea. I put the code in with error handling and its telling me object required and prints a blank report

    Code:
    Private Sub cmdOnPremisePrint_Click()
    On Error GoTo Err_cmdOnPremisePrint_click
    
    'open the report showing only on premise and both
        DoCmd.OpenReport "rptcomboreportqry", , , "rptcomboreportqry.Premise" = "On Premise" Or "rptcomboreportqry.Premise" = "Both"
    'Print the Report
        Docomd.PrintOut acPrintAll
            
    Exit_cmdOnPremisePrint_click:
        Exit Sub
    Err_cmdOnPremisePrint_click:
        MsgBox Err.Description
        Resume Exit_cmdOnPremisePrint_click
    End Sub

  4. #4
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    Try

    DoCmd.OpenReport "rptcomboreportqry", , , "Premise = 'On Premise' Or Premise = 'Both'"

    By the way, you don't need the PrintOut line. The above would print straight to the default printer, since the view isn't specified.
    Paul

  5. #5
    Join Date
    Aug 2012
    Posts
    126
    Quote Originally Posted by pbaldy View Post
    Try

    DoCmd.OpenReport "rptcomboreportqry", , , "Premise = 'On Premise' Or Premise = 'Both'"

    By the way, you don't need the PrintOut line. The above would print straight to the default printer, since the view isn't specified.

    Wow i did not know that about printing thank you so much!

    Also works great. I ran it with the print out line and got the object required line, did it again without it and no error. I see how its failing after your explanation. Thank you again a ton!

  6. #6
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    Happy to help! If you look at VBA help on OpenReport, you can see how you can control whether the report prints or previews to the screen.
    Paul

  7. #7
    Join Date
    Aug 2012
    Posts
    126
    I think I found the flaw with this method. The reports are exactly the same except for that one field (same being same look same title etc etc). After printing both you have no idea which report is which without looking at the data (not a huge deal for this report).

    I really like the way this is set up. IMO its cleaner than creating two additional queries and reports. Does anyone know a way I could put something with the title of the report to differentiate the two? Maybe a control box with a me. command?

  8. #8
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    One way would be to pass something in OpenArgs and have the report change titles based on that.
    Paul

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •