select case question

G

Gary Keramidas

i have a form with 7 option buttons. i am trying to use select case in the code,
but it never evaluates to true. yet, if i break the code and type
?me.optionbutton1.value in the immediate window, it evaluates to true.

can someone tell me what's wrong?

select case test

Case Me.OptionButton1.Value = True
test = 1
Case Me.OptionButton2.Value = True
test = 2
..
..
..

end select
 
R

Randy Harmelink

When you say:
select case test

....you're telling VBA you want to do something based on values of the
variable called "test". Instead, you are giving it conditions.

When you want to specify conditions instead of values for each of the
Cases within the Select Case, your first statement should be:
Select Case TRUE

That tells VBA you are evaluating expressions instead of values for
each Case.
 
G

Guest

Does something like this work for you? Not sure, but it seems like there is
something incorrect about your Case statements.

if Me.OptionButton1.Value then Test=1 else Test=2

select case Test

Case 1
VB action statements here.....

Case 2
VB action statements here.....

end select


Good luck,
Jay
 
G

Gary Keramidas

thanks randy, figured it was something simple. i knew i could use if statements,
but wanted to use select case.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top