Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Toggling Option Group Visibility 1

Status
Not open for further replies.

TechieJr

Instructor
Nov 13, 2002
71
0
0
CA
Hello All,

I'm trying to use the value of one option group to toggle the visibility of a second option group.

The first option group has five options. If option 3 is selected, I want it to make a second option group visible. (Eventually, I will add code to make a third option group visible when option 4 is chosen in the first option group).

Right now I am getting the error:

"Compile error: Expected: = "

when I run the following code:
Code:
Private Sub Frame12_AfterUpdate()
IIf([Frame12]=3,[CPRptCat].Visible = True,[CPRptCat].Visible = False)
End Sub
Frame12 is the first option group with five options. CPRptCat is the second option group which is normally invisible.

Can anyone tell me why I'm getting the error I am? Also, should I be evaluating the frame or the actual option control?

Thanks for sharing your wisdom.
TechieJr.
 
Hi again,

I mistakenly posted the wrong code and error message. The correct error message is:

"Compile error: Syntax error"

and the code is:
Code:
Private Sub Frame12_AfterUpdate()
IIf([Frame12]="3",[CPRptCat].Visible = True,[CPRptCat].Visible = False)
End Sub

Thanks again for your help.
TechieJr.
 
If this is on a form, you don't need the brackets.

IIf(Frame12="3",CPRptCat.Visible = True,CPRptCat.Visible = False)

HTH
 
Hi Rubbernilly,

You're correct, the code is on a form. (Actually, the controls and option groups, etc. are all on the same subform.) However, when I tried removing the brackets I receive the error I reported in my first post.

It's probably something right in front of my face but what?

Thanks.
 
If this is not one side of an equation, then don't use the IIF() function... just use the If..Then syntax:

If Frame12="3" Then
CPRptCat.Visible = True
else
CPRptCat.Visible = False
End if


Or, if you simply must have it on one line:

If Frame12="3" Then CPRptCat.Visible = True else CPRptCat.Visible = False
 
Thanks rubbernilly, that solved the problem! I'm still not clear what the problem was but rewriting the code in the If..Then..Else format worked. I guess you get hooked on one method or another and don't always stop to think about other approaches.

TechieJr.
 
Look at the documentation for IIF(). It returns a value. Specifically, it returns either the True part or the False part. It does not run those pieces as code.

You could have set it as the right side of an equation, where the left was the property you wanted to set:

CPRptCat.Visible = IIf(Frame12="3",True,False)

But at that point, you might as well do this:

CPRptCat.Visible = CBool(Frame12="3")

That's nice and simple and just one command.

HTH
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top