I just stumbled on a shortcut for a 4 case Select block. Here's how most of us would probably do it:
Code:
Select Case SomeTest
Case 1
set this1 rowsource
disable ctl1
Case 2
set this2 rowsource
disable ctl1
Case 3
set this3 rowsource
enable ctl1
set ctl2 value = year
set ctl3 value = year +1
Case 4
set this4 rowsource
enable ctl1
set ctl2 value = year
set ctl3 value = year+1
End Select
I thought "how can I use Select Case 1,2, etc. as one Case and set the rowsource accordingly and write only one line for enabling or setting control value?".
You can't "IF Case = 1 Then..."
The answer is
Code:
Select Case SomeTest
Case 1,2
If 1 Then set this1 rowsource
If 2 Then set this1 rowsource
disable ctl1
Case 3,4
If 3 Then set this3 rowsource
If 4 Then set this4 rowsource
enable ctl1
set ctl2 value = year
set ctl3 value = year+1
End Select
I dropped from 18 to 12 lines. Not a big deal here, but for larger Case blocks (don't read that as Select blocks) I imagine there could be a lot of consolidation. For me, the bigger thing was how to know which Case was True in a multi case block. Then again, I suppose everyone else who helps out here already knew this.
Then again, I did research for "ms access vba which case is true in a multi case block" but saw nothing relevant. HTH someone in the future.
EDIT - Well, somehow I broke it. Instead of getting one of 4 values I'm now only getting one of two. In either Case, both IF's now run, so the end result is that regardless of the Case the second IF is also executing. I tried closing the form and compacting to no avail. If I get it back I'll update.