Cases

L

Leo

Hi -

I am looking for a way to write a certain function in VBA.

I want to say that if a certain value in a combo box
is "x", then run a set of code.

However I do not want to do the following:

If cbb_Box = "x" then
Code A
Else
Code B
End IF

I would like to somehow reference a set of code. Is there
any way to name a set of code in VBA? For example, like on
a Case 1, Case 2, Case 3 basis?

Please help.
Thanks!!
 
T

Tom Wickerath

You're very close. Look up SELECT CASE....END SELECT. The example shown below is for a combo
box bound to a text field (ie. "x", "y", "z"):

Select Case Me.cbb_Box
Case "x"
' Run this code
Case "y"
' Run that code
:
:
:
Case Else
Msgbox "An unknown error has occurred"

End Select



Tom
___________________________________________


Hi -

I am looking for a way to write a certain function in VBA.

I want to say that if a certain value in a combo box
is "x", then run a set of code.

However I do not want to do the following:

If cbb_Box = "x" then
Code A
Else
Code B
End IF

I would like to somehow reference a set of code. Is there
any way to name a set of code in VBA? For example, like on
a Case 1, Case 2, Case 3 basis?

Please help.
Thanks!!
 
M

Mike Labosh

Tom Wickerath nailed it, but I thought I would add an additional thought:

If you come from a C / C++ / Java background, you're used to using switch()
and break; In VBA, there is no break; because each Case block in a Select
Case statement breaks automatically.

--
Peace & happy computing,

Mike Labosh, MCSD

Feed the children!
Save the whales!
Free the mallocs!
 
Top