code to hide controls?

G

Guest

I'd be really grateful if someone could put me right on the following code,
intended to hide certain controls on an invoice report conditional on the
value of a check box. Trouble is the code hides the controls whatever the
value of the check box, and (as is no doubt all too obvious) I have only
miniscule knowledge of VBA.

I had somewhat similar code that worked (without the "Dim ckbIsAgent") to
hide controls for a form but a report seems to be a different kettle of fish.
I put in the Dim ckbIsAgent line when I got an error message saying I'd
entered an expression with no value and the debug highlighted the next line
(the "If..." line). No idea if that was correct.

Here's the code:

Private Sub Report_Open(Cancel As Integer)
Dim ckbIsAgent
If ckbIsAgent = True Then
txtOrderForAddress.Visible = True
lblAgentDiscount.Visible = True
txtAgentDiscount.Visible = True
txtAgentDiscountCalc.Visible = True
Else
txtOrderForAddress.Visible = False
lblAgentDiscount.Visible = False
txtAgentDiscount.Visible = False
txtAgentDiscountCalc.Visible = False
End If
End Sub
 
K

Ken Snell \(MVP\)

Your code never sets a value for ckbIsAgent variable, so that variable has
the Default value of False -- and all your controls are invisible.

Where is the checkbox located -- on a form that is opening the report?
Assuming yes, add this line of code after the Dim statement:

ckbIsAgent = Forms!FormName!CheckBoxName

(replace FormName and CheckBoxName with the real names of the form and
checkbox control).
 
G

Guest

Thanks very much Ken. Not only have you fixed my report but I now also see
how Dim declarations are supposed to work. Big leap forward!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top