Solved

VBA "Select Case" multiple conditions

Posted on 2009-06-30
5
8,715 Views
Last Modified: 2013-11-26
Hi x-perts,

Is there a way to write a Select Case statement with a FEW executable Case options, i.e. when a=true and b = true?

of course, I can write all IF statements, but it would be much easier with Select Case

Thanks
Select Case true

     Case a

     'do something

     Case b 

     'do something

End select

Open in new window

0
Comment
Question by:andy7789
  • 2
  • 2
5 Comments
 
LVL 10

Assisted Solution

by:JPJ78
JPJ78 earned 200 total points
ID: 24751809
I'm sorry, but I don't think you can.
You can write OR statements, but not AND.
OR statements are coma sepparated.


Select Case true

     Case a,c,d

     'do something

     Case b 

     'do something

End select

Open in new window

0
 

Author Comment

by:andy7789
ID: 24751825
I mean not INSIDE of a Case, but execute a few Case statements in a row, if conditions are satisfied, i.e. perform Case a AND Case b

is it possible somehow?
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24752038
you mean:
Select Case true
     Case a OR c OR d
     'do something
     Case b 
     'do something
End select

Open in new window

0
 

Author Comment

by:andy7789
ID: 24752355
Yes, if both the conditions are true, ex a = true and b = true, it will only execute the first, i.e. a=true condition and exit. Case b will not be checked and executed

what I need is to execute ALL individual Case statement, if the conditions are satisfied.
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 300 total points
ID: 24752387
I see. no, that is NOT possible with the CASE statement.
CASE will run and exit on the first match.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now