Best way to write code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have multiple fields that I only want visible when certain criteria is met.
I currently have the following code. Is there a way to combine the criteria
rather than writing out each as Me.lstreports = and the name of the report?

Me.FundPolicy.Visible = (Me.[lstReports] = "Issues by Client Detail" Or
Me.[lstReports] = "Issues by Client Summary" Or Me.[lstReports] = "Apology")
 
Karen

You posted a question in a forms-oriented newsgroup that mentions
"lstReports". Are you working with forms or reports?

The potential downside of the approach you've chosen is that you'd need to
update the code every time a new item in your control (?lstReports?) would
need to have FundPolicy made invisible.

An alternate approach would be to add a field to the table that holds the
items that go into the lstReports. That new field (?[ShowFundPolicy]) could
be a boolean (Y/N) field, and you would return it as a hidden column in your
?list box, using it to set the .Visible property.

NOTE: some users are confused and distracted when items on the screen
disappear and reappear. Another approach would be to set the .Enabled
property, either rendering the control "grayed out" and not accessible or
fully enabled.

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
In
Karen said:
I have multiple fields that I only want visible when certain criteria
is met. I currently have the following code. Is there a way to
combine the criteria rather than writing out each as Me.lstreports =
and the name of the report?

Me.FundPolicy.Visible = (Me.[lstReports] = "Issues by Client Detail"
Or Me.[lstReports] = "Issues by Client Summary" Or Me.[lstReports] =
"Apology")

Here's one way:

With Me.FundPolicy
Select Case Me.lstReports
Case "Issues by Client Detail", _
"Issues by Client Summary", _
"Apology"
.Visible = True
Case Else
.Visible = False
End Select
End With
 
A couple of ideas.
First, you can use the With ... End with contstruction. It is usually
faster and save a little code (not much, but some):

With Me
.FundPolicy.Visible = (.[lstReports] = "Issues by Client Detail" Or
..[lstReports] = "Issues by Client Summary" Or .[lstReports] = "Apology")
End With

Or you could use an Instr Function and reference the control only once:
With Me
.FundPolicy.Visible = INstr("Issues by Client Detail/Issues by Client
Summary/Apology",.[lstReports]) > 0
End With
 
or, (since the OP mentioned multiple fields):

Dim bolVisible as Boolean

Select Case Me.lstReports
Case "Issues by Client Detail", _
"Issues by Client Summary", _
"Apology"
bolVisible = True
Case Else
bolVisible = False
End Select

Me.FundPolicy.Visible =bolVisible
Me.AnotherField.Visible = bolVisible
Me.YetAnotherControl.Visible = bolVisible

HTH,

Dirk Goldgar said:
In
Karen said:
I have multiple fields that I only want visible when certain criteria
is met. I currently have the following code. Is there a way to
combine the criteria rather than writing out each as Me.lstreports =
and the name of the report?

Me.FundPolicy.Visible = (Me.[lstReports] = "Issues by Client Detail"
Or Me.[lstReports] = "Issues by Client Summary" Or Me.[lstReports] =
"Apology")

Here's one way:

With Me.FundPolicy
Select Case Me.lstReports
Case "Issues by Client Detail", _
"Issues by Client Summary", _
"Apology"
.Visible = True
Case Else
.Visible = False
End Select
End With

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
Back
Top