Results 1 to 9 of 9
  1. #1
    kyle87 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Posts
    9

    Macro using IF to set visibility in report

    I have created a report in Access 2010, creatively entitled "Report," with the following (relevant) fields:

    Prog Type
    Relationship
    PROJECT_ID
    SumOfAmount

    I have created text boxes in the Report Footer that count distinct records for Prog Type, Relationship, and Project_ID. The count text boxes are called:

    txtSumProg_Type
    txtSumRelationship
    txtSumPROJECT_ID

    Each of the fields (Prog Type, Relationship, and PROJECT_ID) has its own footer to give a subtotal of SumOfAmount at each level. What I would like to do now is hide certain footers based on the number of unique records. For example, if there is only one Prog Type, I do not need to see the Report Footer because the Prog Type Footer and Report Footer will show the same subtotal.

    What I have tried is to create a Macro called Report_Visibility that runs On Open of Report. I am using the built-in macro functionality because I am not very comfortable with VBA.

    The closest I have been able to come was this attempt:



    If [Reports]![Report]![txtSumProg_Type].[AfterUpdate]="1" Then
    SetProperty
    Control Name ReportFooter
    Property Visible
    Value No
    Else
    SetProperty
    Control Name ReportFooter
    Property Visible
    Value Yes
    End If

    I wanted to get this one right before I move onto hiding the other two sections. What is happening now is that somehow the IF statement is always evaluating to TRUE and hiding my ReportFooter, regardless of the number displaying in txtSumProg_Type (which is either 1 or 3, depending on the filter).

    Any help would be greatly appreciated!!

  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
    You appear to be testing after update instead of value. If you want the VBA:

    http://www.baldyweb.com/ConditionalVisibility.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    kyle87 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2013
    Posts
    9
    Thanks for your recommendation. I'm now getting an error. When I try to run the macro as follows:

    If [Reports]![Report]![txtSumProg_Type]="1" Then
    SetProperty
    Control Name ReportFooter
    Property Visible
    Value No

    Else
    SetProperty
    Control Name ReportFooter
    Property Visible
    Value Yes

    End If

    I get an error "Type mismatch," which is less than helpful. I also tried the above without the quotation marks around the 1 with the same error. Other ideas about what I might be doing wrong?

    Thanks!

  4. #4
    kyle87 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2013
    Posts
    9
    I tried switching over to VBA to see how that would go. I now have the following:

    Code:
    If Me.txtSumProg_Type = 1 Then
        Me.ReportFooter.Visible = False
    Else
        Me.ReportFooter.Visible = True
    End If
    I am getting Run-time error '2424': The expression you entered has a field, control, or property name that Microsoft Access can't find. The debugger then highlights the line containing Me.txtSumProg_Type.

    I don't understand why it can't find it

  5. #5
    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 here? What event is the code in?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    kyle87 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2013
    Posts
    9
    I tried attaching. Let me know if this doesn't work. The VBA runs when Report opens.

    Historical Analysis_scrubbed.zip

  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
    Gotta go to lunch, but try the load event rather than the open event.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    kyle87 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2013
    Posts
    9
    That worked!!! Thanks so much! I'll be able to sleep tonight

  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
    Happy to help! Now if only I could cure my wife's insomnia.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Field visibility in a report
    By PhilTFC in forum Forms
    Replies: 8
    Last Post: 10-29-2012, 12:10 PM
  2. Field Visibility
    By cbrsix in forum Programming
    Replies: 3
    Last Post: 06-27-2012, 03:52 PM
  3. Replies: 0
    Last Post: 01-12-2011, 12:43 PM
  4. Visibility of other controls
    By jlclark4 in forum Forms
    Replies: 7
    Last Post: 12-15-2010, 12:34 PM
  5. Replies: 0
    Last Post: 11-24-2009, 03:23 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