Case statement help

J

JD

Looking for a hand in understanding case statements. Looked up MSFT examples
as well as some of the posts here, but it's not sinking in. I'm tyring to
create a case statement that evaluates the value of a combo box and sets the
value of other combo boxes depenending on whats in it. I'm lost, any help
would be appreciated.
I can do the same tasks with if then's, but it would be messy. New to
coding, any help would be really apprecaited.

Tried a couple variations of the following but it does not work.

Private Sub Combo1_AfterUpdate()
Dim verify as string
verify = me.combo1.value

Select Verify
Case1
verify ="ABC"

Case2
verify ="DEF"

End Select

Select Case Verify
Case1
combo2.value ="true"
combo3.value ="N/A"

Case2
combo2.value ="false"
combo3.value ="true"

End Select
End Sub
 
K

Ken Snell [MVP]

What is the value that would be in Verify?

Normal Case syntax:

Select Case NameOfControlOrVariable
Case "some value"
' code to do something when NameOfControlOrVariable = "some value"
Case "other value"
' code to do something when NameOfControlOrVariable = "other value"
End Select
 
D

Douglas J. Steele

The Case statements need a space between the word Case and the value. The
value is an actual value, too, not a position.

Since your first SELECT CASE structure is resetting the value of the
variable verify to either ABC or DEF. Therefore, I'd expect the second
SELECT CASE structure to refer to values ABC and DEF:

Select Case Verify
Case "ABC"
me.combo2.value ="true"
me.combo3.value ="N/A"
Case "DEF"
me.combo2.value ="false"
me.combo3.value ="true"
End Select
 
D

David C. Holley

The syntax appears to be correct in the 2nd example...

Select Case [expression/variable]
Case [value]
Code:
Case [value]
[code]
Case else
End Select

What exactly is happening that indicates that its not working?
 
J

JD

Ken/Doug/David,

Thanks for the help. I wound up changing the Case statment to follow Ken's
format. With a few changes, i was up and running. The previous code I was
using wouldn't error at runtime, however, the code didn't appear to do
anything. I.e, combo box values wouldn't change. I'm all set with my new
case statment and it works. I got rid of the variable verfiy and just called
the contorl name. Seem'd to do the trick. I appreciate your guys help!

JD





David C. Holley said:
The syntax appears to be correct in the 2nd example...

Select Case [expression/variable]
Case [value]
Code:
Case [value]
[code]
Case else
End Select

What exactly is happening that indicates that its not working?
[QUOTE]
Looking for a hand in understanding case statements. Looked up MSFT examples
as well as some of the posts here, but it's not sinking in.  I'm tyring to
create a case statement that evaluates the value of a combo box and sets the
value of other combo boxes depenending on whats in it. I'm lost, any help
would be appreciated.
I can do the same tasks with if then's, but it would be messy. New to
coding, any help would be really apprecaited.

Tried a couple variations of the following but it does not work.

Private Sub Combo1_AfterUpdate()
Dim verify as string
verify = me.combo1.value

Select Verify
Case1
verify ="ABC"

Case2
verify ="DEF"

End Select

Select Case Verify
Case1
combo2.value ="true"
combo3.value ="N/A"

Case2
combo2.value ="false"
combo3.value ="true"

End Select
End Sub[/QUOTE]
[/QUOTE]
 

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