Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

VBA Combobox Multiple Cases

Status
Not open for further replies.

jzecha

Aerospace
Jan 20, 2016
235
0
0
US
I am trying to write a code to automate inserting hole and I am struggling to get part of my code to work.
I have a section of my code that lets you pick between Simple, Counterbored, and Countersunk holes and lets you put the needed information in.

I have gotten the Simple and Counterbored holes to work perfectly, but the issue is there are three different Countersunk hole styles.
So I tired using the same type of code to allow me to pick between those three styles as well inside the code of the Countersunk hole selection, but it fails.

For reference this section of the code is in a VBA Form:
Code:
index5 = cmbobxHoleType.Value
Select Case index5

Case Is = "Simple"

Case Is = "Counterbored"

hDiameter2MM = frmHoleMenu.txtbxDiameter2.Value
hDepth2MM = frmHoleMenu.txtbxDepth2.Value

Case Is = "Countersunk"

    index6 = cmbobx_CS_Typee.Value
    Select Case index6
    Case Is = "Depth & Angle"
    hDepth2MM = frmHoleMenu.txtbxDepth2.Value
    hAngle2 = frmHoleMenu.txtbxAngle2.Value
    
    Case Is = "Depth & Diameter"
    hDepth2MM = frmHoleMenu.txtbxDepth2.Value
    hDiameter2MM = frmHoleMenu.txtbxDiameter2.Value

    Case Is = "Angle & Diameter"
    hAngle2 = frmHoleMenu.txtbxAngle2.Value
    hDiameter2MM = frmHoleMenu.txtbxDiameter2.Value
    
    End Select

And this section is in the VBA Module:
Code:
'''''
'Setting Up Hole Type (Simple, Tapered, Counterbored...)
Select Case index5
Case Is = "Simple"
oHole.Type = catSimpleHole

Case Is = "Counterbored"
oHole.Type = catCounterboredHole
'Dim oHeadDiameter As Length
Set oHeadDiameter = oHole.HeadDiameter
oHeadDiameter.Value = hDiameter2IN


'Dim oHeadDepth As Length
Set oHeadDepth = oHole.HeadDepth
oHeadDepth.Value = hDepth2IN

oPart.UpdateObject oHole

Case Is = "Countersunk"

        index6 = cmbobx_CS_Typee.Value
        Select Case index6
        Case Is = "Depth & Angle"
        oHole.Type = catCountersunkHole
        oHole.CounterSunkMode = catCSModeDepthAngle

        'Dim oHeadDepth As Length
        Set oHeadDepth = oHole.HeadDepth
        oHeadDepth.Value = hDepth2IN
    
        'Dim oHeadAngle As Angle
        Set oHeadAngle = oHole.HeadAngle
        oHeadAngle.Value = hAngle2IN
    
        oPart.UpdateObject oHole
    
    Case Is = "Depth & Diameter"
        oHole.Type = catCountersunkHole
        oHole.CounterSunkMode = catCSModeDepthDiameter
    
        'Dim oHeadDiameter As Length
        Set oHeadDiameter = oHole.HeadDiameter
        oHeadDiameter.Value = hDiameter2IN


        'Dim oHeadDepth As Length
        Set oHeadDepth = oHole.HeadDepth
        oHeadDepth.Value = hDepth2IN
    
        oPart.UpdateObject oHole

    Case Is = "Angle & Diameter"
        oHole.Type = catCountersunkHole
        oHole.CounterSunkMode = catCSModeAngleDiameter
    
        'Dim oHeadAngle As Angle
        Set oHeadAngle = oHole.HeadAngle
        oHeadAngle.Value = hAngle2IN
    
        'Dim oHeadDiameter As Length
        Set oHeadDiameter = oHole.HeadDiameter
        oHeadDiameter.Value = hDiameter2IN
    
        oPart.UpdateObject oHole
        
        End Select
 
Replies continue below

Recommended for you

That's partially how I got to this area.
I know the variables and how to set them are correct for the features.
I just don't know the best way to use multiple combo boxes in my form for the Countersunk holes.

It's more a question of how to correctly do an Index Case inside an existing Index Case in the code.
Or if this isn't possible, let me know how to handle it better
 
Status
Not open for further replies.
Back
Top