From: Kurt Heisler on
This code will enable txtReason if cboFavColor = "Green," and disable
txtReason if cboFavColor <> "Green":

Me.txtColors.Enabled = IIf(Me.cboFavColor = "Green", -1, 0)

If I want to expand the criteria to include "Green" OR "Blue", can I
do something like:

Me.txtColors.Enabled = IIf(Me.cboFavColor = "Green" OR "Blue", -1,
0)

This doesn't work but I suspect it's because I have the syntax wrong.
Suggestions?



From: Douglas J. Steele on
Me.txtColors.Enabled = IIf(Me.cboFavColor = "Green" OR Me.cboFavColor =
"Blue", -1, 0)

or

Me.txtColors.Enabled = IIf(Me.cboFavColor IN ("Green", "Blue"), -1, 0)


--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)



"Kurt Heisler" <heislerkurt(a)gmail.com> wrote in message
news:62e9d3df-3fbf-401e-8633-75e741682163(a)h31g2000prl.googlegroups.com...
> This code will enable txtReason if cboFavColor = "Green," and disable
> txtReason if cboFavColor <> "Green":
>
> Me.txtColors.Enabled = IIf(Me.cboFavColor = "Green", -1, 0)
>
> If I want to expand the criteria to include "Green" OR "Blue", can I
> do something like:
>
> Me.txtColors.Enabled = IIf(Me.cboFavColor = "Green" OR "Blue", -1,
> 0)
>
> This doesn't work but I suspect it's because I have the syntax wrong.
> Suggestions?
>
>
>

From: John W. Vinson on
On Fri, 23 Apr 2010 21:27:25 -0700 (PDT), Kurt Heisler <heislerkurt(a)gmail.com>
wrote:

>This code will enable txtReason if cboFavColor = "Green," and disable
>txtReason if cboFavColor <> "Green":
>
> Me.txtColors.Enabled = IIf(Me.cboFavColor = "Green", -1, 0)
>
>If I want to expand the criteria to include "Green" OR "Blue", can I
>do something like:
>
> Me.txtColors.Enabled = IIf(Me.cboFavColor = "Green" OR "Blue", -1,
>0)
>
>This doesn't work but I suspect it's because I have the syntax wrong.
>Suggestions?
>
>
OR looks like the English language conjunction, but it isn't. It's an operator
in Boolean Algebra, just as + or - is an operator in arithmatic. It will take
two expressions and return TRUE if either or both of them are TRUE (meaning
not equal to 0, in the VBA universe), and FALSE if they are both false.

The expression

Me.cboFavColor = "Green"

might or might not be true, but

"Blue"

certainly is (it's nonzero); so the control should always enable.

Since the Enabled property is either TRUE or FALSE, you can just use

Me.txtColors.Enabled = (Me.cboFavColor IN ("Green", "Blue"))

--

John W. Vinson [MVP]
From: Kurt Heisler on
Both options ...

John's: Me.txtColors.Enabled = (Me.cboFavColor IN ("Green", "Blue"))

and

Douglass': Me.txtColors.Enabled = IIf(Me.cboFavColor IN ("Green",
"Blue"), -1, 0)

.... give this error:

"Compile error: Expected: ) " and highlight the IN.




On Apr 24, 2:42 am, John W. Vinson
<jvinson(a)STOP_SPAM.WysardOfInfo.com> wrote:
> On Fri, 23 Apr 2010 21:27:25 -0700 (PDT), Kurt Heisler <heislerk...(a)gmail..com>
> wrote:
>
> >This code will enable txtReason if cboFavColor = "Green," and disable
> >txtReason if cboFavColor <> "Green":
>
> >    Me.txtColors.Enabled = IIf(Me.cboFavColor = "Green", -1, 0)
>
> >If I want to expand the criteria to include "Green" OR "Blue", can I
> >do something like:
>
> >    Me.txtColors.Enabled = IIf(Me.cboFavColor = "Green" OR "Blue", -1,
> >0)
>
> >This doesn't work but I suspect it's because I have the syntax wrong.
> >Suggestions?
>
> OR looks like the English language conjunction, but it isn't. It's an operator
> in Boolean Algebra, just as + or - is an operator in arithmatic. It will take
> two expressions and return TRUE if either or both of them are TRUE (meaning
> not equal to 0, in the VBA universe), and FALSE if they are both false.
>
> The expression
>
> Me.cboFavColor = "Green"
>
> might or might not be true, but
>
> "Blue"
>
> certainly is (it's nonzero); so the control should always enable.
>
> Since the Enabled property is either TRUE or FALSE, you can just use
>
> Me.txtColors.Enabled = (Me.cboFavColor IN ("Green", "Blue"))
>
> --
>
>              John W. Vinson [MVP]

From: John W. Vinson on
On Tue, 27 Apr 2010 10:15:02 -0700 (PDT), Kurt Heisler <heislerkurt(a)gmail.com>
wrote:

>Both options ...
>
>John's: Me.txtColors.Enabled = (Me.cboFavColor IN ("Green", "Blue"))
>
>and
>
>Douglass': Me.txtColors.Enabled = IIf(Me.cboFavColor IN ("Green",
>"Blue"), -1, 0)
>
>... give this error:
>
>"Compile error: Expected: ) " and highlight the IN.

Hrm. Rats... can't use SQL syntax in this context!

You'll need to use OR:

Me.txtColors.Enabled = (Me.cboFavColor="Green" OR Me.cboFavColor="Blue")
--

John W. Vinson [MVP]
 |  Next  |  Last
Pages: 1 2
Prev: Combo Box Wizard
Next: countdown timer