By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,984 Members | 2,832 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,984 IT Pros & Developers. It's quick & easy.

Hide a checkbox on a report if its value is false

P: 99
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.
Mar 20 '10 #1

✓ answered by patjones

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

Share this Question
Share on Google+
4 Replies


patjones
Expert 100+
P: 931
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
Mar 20 '10 #2

P: 99
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.
Mar 22 '10 #3

NeoPa
Expert Mod 15k+
P: 31,492
@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?
Mar 22 '10 #4

patjones
Expert 100+
P: 931
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
Mar 22 '10 #5

Post your reply

Sign in to post your reply or Sign up for a free account.