Setting up CASE selection in VBA

Hi,

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.

Anthony
LVL 1
anthonytrAsked:
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.

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.
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
Ryan ChongCommented:
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
https://support.office.com/en-US/Article/Create-a-list-of-choices-by-using-a-list-box-or-combo-box-70abf4a9-0439-4885-9099-b9fa83517603
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.