Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / New Users / July 2006

Tip: Looking for answers? Try searching our database.

code to hide controls?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
David Newmarch - 06 Jul 2006 23:44 GMT
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
Ken Snell (MVP) - 07 Jul 2006 00:18 GMT
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).

Signature

       Ken Snell
<MS ACCESS MVP>

> I'd be really grateful if someone could put me right on the following
> code,
[quoted text clipped - 27 lines]
> End If
> End Sub
David Newmarch - 07 Jul 2006 08:16 GMT
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!

> Your code never sets a value for ckbIsAgent variable, so that variable has
> the Default value of False -- and all your controls are invisible.
[quoted text clipped - 38 lines]
> > End If
> > End Sub
Ken Snell (MVP) - 07 Jul 2006 16:51 GMT
You're welcome.

> 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!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.