Setting up CASE selection in VBA


I sometimes use CASE selections in VBA when dealing with user selections, for example in MsgBox questions with vbYesNO answers.  However I can't fathom out how to do a similar thing but with a dropdown box selection.

I need 4 different cases to run based on 4 possible selections from a dropdown text box on my form.   The 4 possible cases are:
'Case 1 CD-R or DVD-R
'Case 2 CD-RW or DVD-RW
'Case 3 Flash Drive
'Case 4 Zip and Email

Each case would obviously run a different piece of  code.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

Anders Ebro (Microsoft MVP)Microsoft DeveloperCommented:
Just seperate the values with a comma.
Select Case me.Dropdownname
Case "CD-R","DVD-R"
Case "CD-RW", "DVD-RW"
Case "Flash Drive"
Case "Zip","Email"
Case Else
End Select

Open in new window

It usually a good idea to add a case else, so if you later make a change to the combobox, but forget to update your code, the case else could include a msgbox warning, or even raise an error.

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
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
yes, use a select case statement will do, what you need to do is to retrieve the dropdown list's value or relevant properties that you required, like:
v = yourDropdown.Value
'if you would like to get the dropdown text instead
'v = yourDropdown.Column(1, yourDropdown.ListIndex)

Select case v
case 1
   call yourFunction1
case 2
   call yourFunction2
case 3
   call yourFunction3
case 4
   call yourFunction4
end select

Open in new window

the value to compare ( "v") it depending what values you set in your dropdown (combox) box.

This link may help you to further understand how to create a dropdown with values.
Create a list of choices by using a list box or combo box
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.