Hide a checkbox on a report if its value is false

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • julietbrown
    New Member
    • Jan 2010
    • 99

    Hide a checkbox on a report if its value is false

    In the detail section of a report I want to hide a checkbox control and it's label if the value of the control is false. I sort of expected the following to work.

    Code:
    Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
          If Me.CheckBox1 = True then
                Me.CheckBox1.Visible = True
          Else
                Me.CheckBox1.Visible = False
          End If
          'or, more obscurely, in one line "Me.CheckBox1.Visible = Me.CheckBox1"
    End Sub
    However, it DOESN'T!! The code has no effect at all. If I replace it by just one line ...

    Code:
          Me.CheckBox1.Visible = False    'just for experimental purposes
    ... again, the code seems to have no effect at all. Check box still there!!!
    I'm sure (thinking back to my ancient Access 2003 days) I was able to do this conditional report formatting once upon a time. This granny possibly approaching senility.
  • patjones
    Recognized Expert Contributor
    • Jun 2007
    • 931

    #2
    Hi juliet -

    If you could do one little thing, which is to insert

    Code:
    MsgBox "Hello"

    somewhere in the subroutine, and then try running it again, this might shed light on the problem. I think it might be possible that your subroutine isn't even running; whether the message box shows up or not will tell us if that is the case.

    Pat

    Comment

    • julietbrown
      New Member
      • Jan 2010
      • 99

      #3
      Thnaks ... that is a good idea, but actually I already tried it! The sub is running, but not doing what I told it!!! I'll let you know if/when I solve the problem.

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32634

        #4
        Originally posted by julietbrown
        The sub is running, but not doing what I told it!!!
        Disobedient procedures!! Shock! Horror!

        Have you tried tracing through the code (Debugging in VBA) Juliet, to determine which actual lines of code are executing, and if the specific line is executing, what is happening?

        Comment

        • patjones
          Recognized Expert Contributor
          • Jun 2007
          • 931

          #5
          In asking my question, I was trying to get at when exactly this event runs.

          For the mock report that I made, I found that the event runs when you hit "Print Preview", but it does not seem to run when you simply "Open" the report.

          So, when I inserted the code

          Code:
          Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
          
          Me.chkTest.Visible = Me.chkTest
          
          End Sub

          I found that it worked fine in Print Preview and Export to PDF. But it did not work with Open.

          Pat

          Comment

          Working...