ActiveX command buttons and list boxes not working in a UserForm

seleseped

Board Regular
Joined
Feb 1, 2005
Messages
59
Hello,
I'm trying to write only my second UserForm and have bitten off more than I can chew! Here's hoping that some kind soul will be able to help me out.

I'm using Excel 2010. My user form contains a series of frames which contain text boxes, labels, list boxes, option buttons and/or command buttons (I'll call these frames and the objects they contain "frame sets"). Depending on the responses to one of the objects in a frame, another frame set will appear or disappear as the user is led through a series of questions.

I'm having two problems:
The ActiveX command buttons, when clicked, do not elicit a response (that is, the next frame does not appear or disappear as it should). Here's an example of the code (contained in the UserForm1 module) for one of the command buttons:
Code:
Public Sub cmdContinueFromMechanicalValve_Click()
    If lstValveMechanical.ListCount < 0 Then
            HideSchedProcedure           'this hides the frame set named 'SchedProcedure'
            HideVTE                             'this hides the frame set named 'VTE'
            MsgBox "You have not selected a mechanical valve type(s).", vbCritical, "Mechanical valve type not selected"
        ElseIf lstValveMechanical.ListCount = 0 _
            Or lstValveMechanical.ListCount = 1 Then
                HideValveBioprosthetic           'this hides the frame set named 'ValveBioprosthetic'
                ShowSchedProcedure             'this unhides the frame set named 'SchedProcedure'
        ElseIf lstValveMechanical.ListCount = 2 Then
            HideSchedProcedure           'this hides the frame set named 'SchedProcedure'
            ShowValveBioprosthetic      'this unhides the frame set named 'ValveBioprosthetic'
    End If
End Sub

My second problem is with the list boxes . . .
The list boxes contain lists of 3-5 items, the last one being 'None of the above.' I would like to write code that, when that item is selected, de-selects any other items above it that may have been checked. Again, I cannot figure out how to write code that will do that. (I do know that List Items are numbered starting with zero.) Here's what I've written . . .
Code:
Private Sub lstVTE_Click()
' Clears previously selected options when 'none of the above' is clicked

 If lstVTE.ListIndex = 5 Then    'ListIndex item 5 is 'None of the above'
    lstVTE.Clear
    lstVTE.ListIndex = 5            'Re-selects item 5
End If
End Sub

I am happy to attach the actual file but cannot figure out how to do so. I would willingly e-mail it to anybody who's willing to help me.

I've gotten a lot of help from members of this forum in the past. Please know that your willingness to help out random, anonymous strangers is much appreciated.
Michele
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Michele

Have you checked if the command button click event(s) are being triggered?

You can do that by putting a breakpoint on the first line of the click event using F9, opening the form and clicking the button.

If the event(s) are being triggered you code execution should be interrupted at the point you put the break.

As for the listboxes, why are you using Clear?

I thought you wanted to clear the selected items not the listbox itself.
 
Upvote 0
Thank you for the quick response, Norie. You've helped me in the past and I much appreciate it.

I've checked the command button click event as you suggested and yes, indeed, the event is triggered (that is, the line of code is highlighted where the breakpoint is placed and continues through the code as F8 is pressed) but nothing happens on the form (e.g., the new frame set does not appear as it should). That must mean that the problem is then with how I'm coding/calling subsequent events? In the example I gave, here's the code for two of the subsequent events:
Code:
Public Sub ShowSchedProcedure()
    fraProcedure.Visible = True             'Pending procedure? yes
        lblProcedure.Visible = True
        OptProcedureYes.Visible = True
            OptProcedureYes.Value = False
        OptProcedureNo.Visible = True
            OptProcedureNo.Value = False
End Sub

Public Sub HideValveBioprosthetic()
    lstValveBioprosthetic.Visible = False
    cmdContinueFromBioprostheticValve.Visible = False
End Sub

As for why I'm using Clear in my list box . . . my ignorance is showing. What is the code that I should use to de-select individual list box items?

Thank you once more.

Michele

Have you checked if the command button click event(s) are being triggered?

You can do that by putting a breakpoint on the first line of the click event using F9, opening the form and clicking the button.

If the event(s) are being triggered you code execution should be interrupted at the point you put the break.

As for the listboxes, why are you using Clear?

I thought you wanted to clear the selected items not the listbox itself.
 
Upvote 0
FYI, the Listcount can't be less than 0.
 
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,380
Members
449,080
Latest member
Armadillos

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top