Select case with multiple criteria for each case?

I need to execute code based on the value of a control on one form in combination with the value on a second form. Is this doable in Select Case or do I need to be doing a series of nested If...Thens?

Here's a crack at it in Select Case

    Select Case Forms!frmSavedValue!txtUbSaved AND forms!frmMain!fsubGrtOrg.form!cboStatusK
           
        Case "cmdGrt" and "External":
                 instructions......
eliwilAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dqmqCommented:
Well THAT won't work!  Do it like this:

 Select Case Forms!frmSavedValue!txtUbSaved & vbnullchar &  forms!frmMain!fsubGrtOrg.form!cboStatusK
      Case "cmdGrt" & vbnullchar &  "External":
0
Leigh PurvisDatabase DeveloperCommented:
Although when you're into multiple criteria then you are usually better off with an If statement.
Saves jumping through hoops
0
LambertHeenanCommented:
If you don't want an messy set of Ifs then I'd go for a set of nested Select Case statments

Select Case Forms!frmSavedValue!txtUbSaved
    Case "cmdGrt"
    Select Case forms!frmMain!fsubGrtOrg.form!cboStatusK
        Case "External"
            Some Code
        Case "Interal"
           More Code
        End Select
    Case "cmdSomthinElse"
    Select Case forms!frmMain!fsubGrtOrg.form!cboStatusK
        Case "External"
            Some Code
        Case "Interal"
           More Code
        End Select
End Select

Still a bit messy, but not as bat as the IF Them verions IMHO.

If all the nested case options are the same, then you could hide the inner Select Case statement by just calling a function in the outer Case, passing in the test value and have the function use a Select Case statement to figure out what to do. Otherwise just cut and paste the inner select case statement.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

hnasrCommented:
You may split it into 2 Case statements
Select Case Forms!frmSavedValue!txtUbSaved & vbnullchar &  forms!frmMain!fsubGrtOrg.form!cboStatusK
      Case "cmdGrt"
             Select Case forms!frmMain!fsubGrtOrg.form!cboStatusK  ' repeat this with every case of the outer case
                    Case   "External"
                      .......

            End Select
.....
End Select
, One for Forms!frmSavedValue!txtUbSaved, the other nested for forms!frmMain!fsubGrtOrg.form!cboStatusK
0
eliwilAuthor Commented:
If Forms!frmSavedValue!txtUbSaved = "cmdGrt" And frms!frmMain!fsubGrtOrg.form!cboStatusK = "External" or "Applied for" Then

would this statement work? not at all sure of the punctuation.
0
dqmqCommented:
Or you can nest selects:
Or you can nest If/then within the select:

Select Case Forms!frmSavedValue!txtUbSaved
 Case "cmdGrt":
       Select Case forms!frmMain!fsubGrtOrg.form!cboStatusK
        Case "External":
        ...
        End Select
 Case "xxxxxx":
      If  forms!frmMain!fsubGrtOrg.form!cboStatusK = "External" Then
         ...
      End If
 ...
End Select

I do agree with LPurvis:  readability/maintainability is more important that consolidating your tests into the fewest lines possible.

Also, "cmdGrt" looks suspiciously like the name of a control rather than the value of one????????????


0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.