Connect with Expertise | Find Experts, Get Answers, Share Insights

Hide a checkbox on a report if its value is false

 
Join Date: Jan 2010
Location: Swindon, UK
Posts: 88
#1: Mar 20 '10
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.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
  2.       If Me.CheckBox1 = True then
  3.             Me.CheckBox1.Visible = True
  4.       Else
  5.             Me.CheckBox1.Visible = False
  6.       End If
  7.       'or, more obscurely, in one line "Me.CheckBox1.Visible = Me.CheckBox1"
  8. End Sub
  9.  
However, it DOESN'T!! The code has no effect at all. If I replace it by just one line ...

Expand|Select|Wrap|Line Numbers
  1.       Me.CheckBox1.Visible = False    'just for experimental purposes
  2.  
... 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.
best answer - posted by zepphead80
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

Expand|Select|Wrap|Line Numbers
  1. Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
  2.  
  3. Me.chkTest.Visible = Me.chkTest
  4.  
  5. End Sub

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

Pat

zepphead80's Avatar
E
C
 
Join Date: Jun 2007
Location: New York City
Posts: 590
#2: Mar 20 '10

re: Hide a checkbox on a report if its value is false


Hi juliet -

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

Expand|Select|Wrap|Line Numbers
  1. 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
 
Join Date: Jan 2010
Location: Swindon, UK
Posts: 88
#3: Mar 22 '10

re: Hide a checkbox on a report if its value is false


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.
NeoPa's Avatar
E
M
A
C
 
Join Date: Oct 2006
Location: London - UK
Posts: 18,260
#4: Mar 22 '10

re: Hide a checkbox on a report if its value is false


@julietbrown
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?
zepphead80's Avatar
E
C
 
Join Date: Jun 2007
Location: New York City
Posts: 590
#5: Mar 22 '10

re: Hide a checkbox on a report if its value is false


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

Expand|Select|Wrap|Line Numbers
  1. Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
  2.  
  3. Me.chkTest.Visible = Me.chkTest
  4.  
  5. End Sub

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

Pat
Reply

Tags
conditional formatting, report, show/hide fields