Share via

Ms Access - Hide report details programmatically

Anonymous
2011-03-02T08:11:35+00:00

Re: MS Access Reports = Hide Details

I have a form that passes criteria to a Report.

The form has an UNBOUND check box named Forms![QBF_Form01]![HideDetail]

Whether the box is checked or not, I always get Report with full details

I want to offer the user two Report options - one with Detail and one without

Novice here - have not been able to suppress report details using any of the methods below:

    • In the Details section of the Report

In the Event section - "On Format" field reads "Cancel = Forms![QBF_Form01]![HideDetail]"

Running report from form, all records are displayed - Doesn't seem to Cancel "On Format"

    • VBA Code - From the VB editor from within Access, the "tree" on the left of the Code pane:

MS Office Access Class Object

Report_QBF_Report01

Detail:Format

In the Code pane, the Code reads:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

If Forms![QBF_Form01]![HideDetail].Value = True Then

Detail.Visible = False

End If

End Sub

have tried with and without square brackets [ ]

Consistently produces report with all details

    • Me.Section(0).Visible = Forms![YourFormName]![YourControlName]

Found this elsewhere..."Me.Section(0).Visible = Forms![YourFormName]![YourControlName]

Put the code in the Open event of the Report, not the form. It will

reference the form for the true or false to display the detail."

I put the following code in the "On Open" event for the Report:

Me.Section(0).Visible = Forms![QBF_Form01]![HideDetail]

Upon filling the form, click to Run, Access returns:

MS Acces cannot find Object 'Me' - Stalls - No output at all

I'm almost ready to make two reports - but it seems there should be a better way to interpret a "tick" for Details.

I am grateful for any help!

GG

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
Answer accepted by question author
  1. Anonymous
    2011-03-02T14:06:34+00:00

    As long as the form remains open while the report is open, I would expect any of those three techniques to work.

    A reason why the first two do not do anything could be because you are opening the report in Report View, which, AFAIK, does not run any VBA code.  See if you get the desired effect when you open the report in Print Preview.

    The error in your third approach indicates that you put the code in the OnOpen property, not in the Open event procedure.  The event property should be set to:

       [Event Procedure]

    0 comments No comments
Answer accepted by question author
  1. Anonymous
    2011-03-02T13:20:00+00:00

    If you place the code in the reports onpen event, you should

    be able to turn off, or on the detail section.

    I used the following code for years:

    If Forms!GuiGroupDeposit!chkDetail = True Then

    ' summary only button checked...

          Me.Detail.Visible = False

    End If

    So, try using the on open event as per above.

    Albert D. Kallal  (Access MVP)

    Edmonton, Alberta Canada

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Anonymous
    2011-03-02T17:44:57+00:00

    1)  Me.is a VBA thing, but it only applies to class modules, which includes form/report modules, but not to other objects that can not have a module, such as tables.

    2)  These things are a consequence of the object model, an object's properties and an intuition of what happens when you combine them.  For example, report objects have sections, sections have a Visible property and setting a section's Visible property to False kind of intuitively implies that you will not see the section.

    0 comments No comments
  2. Anonymous
    2011-03-02T17:17:58+00:00

    Great answers!  Thanks and kudos to both Albert and Marshall - Both answers gave me a solution.  Hopefully my hair grows back soon - been struggling with this for HOURS - Thanks thanks thanks.

    Besides my misplacement of some [EventProcedure] code (thanks, Marshall), I was never using print preview, therefore never observed the suppression of Details.

    Based on my experience, I'd like to share what I learned....

    Using the OnFormat method.....

                    DesignView-Details-On Format-"Cancel = (Some true statement)"

    works in "PrintPreview" View, but not in "Report" view. 

    Using the OnOpen method  (thanks, Albert)......

                    VB-ClassObjects-ReportName

                        Report(PullDown) - Open (PullDown)

                             Code:

                                       Private Sub Report_Open(Cancel As Integer)

                                             If Forms!QBF_Form01!HideDetail = True Then

                                                       Me.Detail.Visible = False

                                             End If

                                      End Sub

    Produces results in the "Report" view - then you can PrintPreview or Print from there.

    Nice!!!

     I dummied-up this post for NuB's like me - might help next poor soul. 

    Couple of (NuB) questions that I now have......

    1. What is me.whatever - I mean the "me" part - I hate to sound so ignorant - I assume "me." is a shortcut for currently open object, and equates to "ObjectType!ObjectName!" of the currently open object (Report, form, table, query, etc) but how in the heck would I ever have known to use a "me.whatever" expression??  Maybe this is a VB question.
    2. How would I know that Me.Detail.Visible = False

        is the rough equivalent of

        Report-Details-Visible-No

       Is there a VB cheat sheet I could use next time?

    Apologies in advance for my lack of understanding these elementary concepts, and thank you for your help.

    gg

    0 comments No comments