Hide a subreport based on the result from a checkbox in the main form

Posted on 2008-11-07
Last Modified: 2013-11-28
I have a report with several subreports that show up on the report based on if they have data in a specific table or not.  I need to be able to hide one of these subreports in the main report if I have a check box selected or not selected in the main form.  Can this be done by VBA code in the report?  I am not sure how for it to check the main form.  
Question by:thirdrockit
    LVL 44

    Accepted Solution

    in the Current event of the checkbox named chkBox:

    Private Sub chkBox_Current()
      If Me!chkBox Then
        Me.Form!sfmName.Visible = False
        Me.Form!sfmName.Visible = True
      End If
    End Sub

    Author Comment

    I am not hiding a subform, I need to hide a subreport that is within a big report that has a lot of resume data in it.  I have a resume form that has several checkboxs so that my resume data can be selectable for what I want printed.  The data, once selected on the form, is then sent to a table.  The report, with the multiple subreports, pulls the info from the table.  Everything works great except now I have some data going to the table that will automatically cause the subreport to show.  I cannot stop the data from making it to the table so I need to just hide the subreport instead.
    LVL 20

    Assisted Solution

    Create a public variable:
    public glbHideSub as boolean

    In the code prior to opening the report -
    If {your condition = true) then
        glbHideSub = true
    end if

    In the report ON OPEN EVENT
    me.YourSubReport.visible = not glbHideSub

    don't forget to 'clear' the variable on closing the report:
    glbHideSub = false

    Scott C
    LVL 44

    Expert Comment

    OK in my code where you see Form, replace it (it it there two time) with Report

    Author Comment

    Thanks for you help !!! I figured out how to do it so that when the box is checked it changes the data that the report is pulling from.   Unless the box is checked the data will not be in the table, and the sub report will not show because there is no data. I am awarding you all the points anyways because I may still be able to use your examples.
    LVL 44

    Expert Comment

    Thanks, glad to help.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
    Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
    Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
    With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now