Mulitple If's in a function ?

S

Steph

Morning all, what I would like to do is when a checkbox is checked, hide
about 7 different controls. I am having success doing it with ONE, but
failing after that. I tried using a function and then calling it from my
Form's On Current AND the Checkbox After Update. With the single line in
there, like this:

Public Function MISLE_only()
If Me.MISLE_case_only = True Then Me.cmdACTSUS_PIW.Visible = False Else
Me.cmdACTSUS_PIW.Visible = True
End Function

NO problems, works great. How can i add the other controls I want to close
when checkbox Me.MISLE_case_only is checked?

Thanks in advance!

Steph
 
A

Al Campagna

Steph,
A common method is to use the control's Tag property
Give each of the controls you want to hide/unhide, a tag text value
of "CaseOnly"
Using the AfterUpdate event of MISLE_Case_Only...

Dim Ctl as Control
If Me.MISLE_Case_Only = True Then
For Each Ctl In Me.Controls
If Ctl.Tag = "CaseOnly" Then
Ctl.Visible = False
End If
Next Ctl
ElseIf Me.MISLE_Case_Only = False Then
For Each Ctl In Me.Controls
If Ctl.Tag = "CaseOnly" Then
Ctl.Visible = True
End If
Next Ctl
End If

Tested... and that should do it.
--
hth
Al Campagna
Microsoft Access MVP 2006-2009
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your life."
 
J

Jack Leach

Try something like this:

If Me.MISLE_case_only = True Then
Me.SomeControl1.Visible = False
Me.SomeControl2.Visible = False
Me.SomeControl3.Visible = False
Else
Me.SomeCOntrol1.Visible = True
Me.SomeControl2.Visible = True
Me.SomeControl3.Visible = True
End If

This might be simplified by doing this...

Me.SomeControl1.Visible = Not Me.MISLE_case_only
Me.SomeControl2.Visible = Not Me.MISLE_case_only
Me.SomeControl3.Visible = Not Me.MISLE_case_only


hth
--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 
S

Steph

that is great stuff, thanks Al!

Al Campagna said:
Steph,
A common method is to use the control's Tag property
Give each of the controls you want to hide/unhide, a tag text value
of "CaseOnly"
Using the AfterUpdate event of MISLE_Case_Only...

Dim Ctl as Control
If Me.MISLE_Case_Only = True Then
For Each Ctl In Me.Controls
If Ctl.Tag = "CaseOnly" Then
Ctl.Visible = False
End If
Next Ctl
ElseIf Me.MISLE_Case_Only = False Then
For Each Ctl In Me.Controls
If Ctl.Tag = "CaseOnly" Then
Ctl.Visible = True
End If
Next Ctl
End If

Tested... and that should do it.
--
hth
Al Campagna
Microsoft Access MVP 2006-2009
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your life."




.
 
S

Steph

Ok, now I am getting greedy!! How can I basically do the same thing to a
report? I have a report that prints right from a Form, taking only the
information in the last record. Can I modify my reports controls the same way
(I am guessing no), or if not, is there a way to open a different report
based on the true/false of my MISLE_case_only checkbox?

Thanks again, having a blast!

Steph
 
A

Al Campagna

Steph,
Additional note regarding form Tags... using the Tag method, many more
fields
can be made to obey the code just by giving them the CaseOnly Tag.
(You can select multiple text controls, and set each one's Tag in just
one Tag entry)
----------------
Use that Report Section's OnFormat event to evaluate
Forms!frmYourFormName!MISLE_Case_Only
If True, use the same method (and the same code for that matter) to
hide/show the report controls with CaseOnlt Tags.
--
hth
Al Campagna
Microsoft Access MVP 2006-2009
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your life."
 
J

Jack Leach

I agree about using tags... quite easier in most cases. To be a little picky
and make the code a bit more elegant and less to type, you could simplify...

Dim ctl As Control
For Each ctl In Me.Controls
If ctl.Tag = "CaseOnly" Then ctl.Visible = Me.MISLE_case_only
Next ctl

--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 
J

Jack Leach

Rather...

If ctl.Tag = "CaseOnly" Then ctl.Visible = Me.MISLE_case_only

s/b

If ctl.Tag = "CaseOnly" Then ctl.Visible = Not Me.MISLE_case_only

--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 
J

Jack Leach

But I should also mention that Al's solution provides handling of Nulls for a
triplestate checkbox, whereas mine would have to be wrapped with Nz() and
have Nulls treated as False.


--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 

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