Case Statement working intermittently (1 Viewer)

Gasman

Enthusiastic Amateur
Local time
Today, 13:16
Joined
Sep 21, 2011
Messages
14,269
My expectation is that the select case block will look compare each group to the first case and, if it is true then change the header background to the appropriate color, then check it against the second group and if it is true change the background color to green, then the third one and change the color appropriately.

Your response that it will not work for more than one does not make sense to me as it works on the first, third, and fourth, but not the second. And it doesn't matter if I move the second one up or down in the list. It doesn't like the comparison for that particular item.

Tim
No !
It will work on the first case it finds true and that is it. One test per call.
If none are True it will use the Else statement if one is supplied.

If it does not work for a particular case, then that is because that statement does not equate to being true.?
 

Minty

AWF VIP
Local time
Today, 13:16
Joined
Jul 26, 2013
Messages
10,371
Double-check the spelling of Government?
The statement definitely needs to be in the On Format event of whatever section the controls are set in.

The government section sets everything to Black except the back colour of one control, is it not that you just can't see things ??
 

thabart

New member
Local time
Today, 08:16
Joined
May 22, 2020
Messages
14
No !
It will work on the first case it finds true and that is it. One test per call.
If none are True it will use the Else statement if one is supplied.

If it does not work for a particular case, then that is because that statement does not equate to being true.?
so the first group turns blue - like it should, the second group does not work, the third group turns red - like it should. Since it has to stop working after the first true case, how does it turn the third group red?

Tim
 

Micron

AWF VIP
Local time
Today, 08:16
Joined
Oct 20, 2018
Messages
3,478
My expectation is that the select case block will look compare each group to the first case and, if it is true then change the header background to the appropriate color, then check it against the second group and if it is true change the background color to green, then the third one and change the color appropriately.
They do not work that way. If the first case is true, the block is exited. If the second case is true, the block is exited - etc. If none are true, the Else case runs if there is one; if not, the block does nothing. So as soon as one case is true, the rest are not evaluated.
If testexpression matches an expressionlist expression in more than one Case clause, only the statements following the first match are executed.

Maybe that isn't your issue and if it isn't, then when you solve it, it appears it still won't do what you expect.
 

Isaac

Lifelong Learner
Local time
Today, 05:16
Joined
Mar 14, 2017
Messages
8,777
I actually feel- I could be wrong - like something is getting lost in translation here. I think the Select Case actually is just fine for what you are trying to do, you just stated the Select Case expectations a little incorrectly (as others have already pointed out).

Here is how I see it in summary.

The select case statement will evaluate each statement, and exit the block on the first one that evaluates to True.
And since you have several mutually exclusive conditions, only one of which might be true, that should suit your situation exactly, regardless of whether you did or didn't state it perfectly.

Line of business can only be one value at a time ... And I think Select Case would be just fine here. All semantics aside.
 

Isaac

Lifelong Learner
Local time
Today, 05:16
Joined
Mar 14, 2017
Messages
8,777
so the first group turns blue - like it should, the second group does not work, the third group turns red - like it should. Since it has to stop working after the first true case, how does it turn the third group red?

Tim
Isn't there only one condition that could possibly be True? Can Line_Of_Business be multiple values at the same time or just one?
 

Micron

AWF VIP
Local time
Today, 08:16
Joined
Oct 20, 2018
Messages
3,478
so the first group turns blue - like it should, the second group does not work, the third group turns red - like it should. Since it has to stop working after the first true case, how does it turn the third group red?
Anything about that would just be speculation - like there is other code or conditional formatting coming into play. If you can post a compacted and zipped db copy it would help a lot.
 

Users who are viewing this thread

Top Bottom