Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you Select Case? 1

Status
Not open for further replies.

HMJ

Technical User
Nov 29, 2002
58
US
I am trying to use three option buttons in an option group to allow my users to select which information they want to see. (Eventually, it will be a drill-down type of operation.)

Anyway, I have never used the select case function, and am having trouble getting it to work. My current form has the option group with three choices, and then the 'next step' button. Clicking the 'next step' button runs VBA code that says...

Private Sub Next_Click()
Select Case Index
Case Is = 1
MsgBox "Option 1"
Case Is = 2
MsgBox "Option 2"
Case Is = 3
MsgBox "Option 3"
Case Else
MsgBox "DUH"
End Select
End Sub

When I do this, all I get is the Case Else response.
Can anyone help me?

Thanks
Harry J.

Harry Jessen
HMJessen@Yahoo.com
 
Try this instead:
Code:
Private Sub Next_Click()
    Select Case Index
        Case 1
        MsgBox "Option 1"
        Case 2
        MsgBox "Option 2"
        Case 3
        MsgBox "Option 3"
        Case Else
        MsgBox "DUH"
    End Select
End Sub
Is that any better?
How is [tt]Index[/tt] set to a value?



________________________________________
[hippy]Roger J Coult; Grimsby, UK
In the game of life the dice have an odd number of sides.
 
Hi Harry,

There is nothing obviously wrong with your Select so we need to consider what else it might be.

To begin, what is Index? Is it your Option Group or a variable? Can you break the code and see what value it has?

Enjoy,
Tony

------------------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading FAQ222-2244 before you ask a question.
 
Tony:

The 'INDEX' is something I picked out of a reference book. As I indicated - this is a new feature/operation for me and I am lost.

The option buttons are named 'Option1', 'Option2' and 'Option3'. The values are 1, 2, and 3. (Trying to keep it simple for now! I believe the Option Group is called "Frame 10". Once I can get the msgbox to work for each option, I can go from there.)

The button 'next' then executes the code.

Roger:
No change. It still goes to 'Case Else', and I hate seeing "DUH" come up!

Thank you both for your help.


Harry Jessen
HMJessen@Yahoo.com
 
You need to set the value of [tt]Index[/tt] to the value of the [tt]SelectedIndex[/tt] property of the list box before the [tt]Select Case[/tt] statement, otherwise [tt]Index[/tt] has no value and, as you've discovered, will always cause the [tt]Case Else[/tt] clause to be executed.

________________________________________
[hippy]Roger J Coult; Grimsby, UK
In the game of life the dice have an odd number of sides.
 
Hi Harry,

Index is your problem, then. What you want is the value of the option group so try ..

Code:
Select Case Me.Frame10
etc.

Enjoy,
Tony

------------------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading FAQ222-2244 before you ask a question.
 
Got It!!

Thank you for your help! A star to you!

Harry Jessen
HMJessen@Yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top