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
 

Some videos you may like

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
75,562
Office Version
365
Platform
Windows
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.
 

seleseped

Board Regular
Joined
Feb 1, 2005
Messages
59
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.
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
35,012
Office Version
365, 2019, 2016, 2010
Platform
Windows, MacOS
FYI, the Listcount can't be less than 0.
 

Watch MrExcel Video

Forum statistics

Threads
1,099,569
Messages
5,469,462
Members
406,653
Latest member
CBeeker

This Week's Hot Topics

Top