Results 1 to 9 of 9
  1. #1
    pthom is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2016
    Posts
    6

    Report field visibility macro based on yes/no

    Hi, I am trying to make a report that has certain fields visible or not depending on if another field is checked "Yes/NO". I currently have this as my code: [Code]Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    If Me.[Invoices Extended].[Percent Split] = True Then
    Me.PrSplitAmount_2.Visible = True
    Me.PrSplitAmount_3.Visible = True
    Me.Invoice_Total.Visible = True
    Else
    Me.PrSplitAmount_2.Visible = False
    Me.PrSplitAmount_3.Visible = False
    Me.Invoice_Total.Visible = False
    End if
    End Sub
    [code]



    and nothing is happening. The fields that should not be showing are still visible. Any help of insight would be amazing! Thank you!

  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,518
    Let's start with what you're opening the report in. This code won't fire in Report view, only Preview and Print. Is there a subreport?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    pthom is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2016
    Posts
    6
    Paul, thank you for your response! It really only matters how the report prints out - not so much viewing. I tried to view it in print preview and i keep getting the error to be at the [code] If me.Invoices_Extended_Percent_Split = True then [code] segement

  4. #4
    pthom is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2016
    Posts
    6
    Paul, I changed the code to be in the "On Print" of the detail and it will pull up correctly in the print preview. Which will work - but do you know if there is a way to do that while in report view?

  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,518
    Try the On Paint event.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    pthom is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2016
    Posts
    6
    Paul, that didn't work for me either. It's now wanting me to change the else of the code.

  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,518
    If the On Format code was working in Preview mode, the same code in the On Paint event should work in Report view. What's the code now?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    pthom is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2016
    Posts
    6
    The code is:
    [Code]
    Private Sub Detail_Paint()
    If Me.Invoices_Extended_Percent_Split = True Then
    Me.Invoices_Extended_Percent_Split_1.Visible = True
    Me.Invoices_Extended_Percent_Split_2.Visible = True
    Me.Invoices_Extended_Percent_Split_3.Visible = True
    Else
    Me.Invoices_Extended_Percent_Split_1.Visible = False
    Me.Invoices_Extended_Percent_Split_2.Visible = False
    Me.Invoices_Extended_Percent_Split_3.Visible = False
    End If
    End Sub
    [code]

    I keep getting a debug error "you can't change the value of this property in the OnPaint event.

  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,518
    I can duplicate that in a brief test. I've used it to change borders and such, so perhaps setting the fore color to match the back color will give you the same effect as setting visible to false.
    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. Macro using IF to set visibility in report
    By kyle87 in forum Macros
    Replies: 8
    Last Post: 07-23-2013, 01:24 PM
  2. Replies: 5
    Last Post: 07-11-2013, 02:19 PM
  3. Replies: 2
    Last Post: 01-31-2013, 07:44 PM
  4. Field visibility based on ComboBox selection
    By cactuspete13 in forum Forms
    Replies: 3
    Last Post: 01-30-2013, 03:37 PM
  5. Field visibility in a report
    By PhilTFC in forum Forms
    Replies: 8
    Last Post: 10-29-2012, 12:10 PM

Tags for this Thread

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