Userform Controls Fail To Trigger After Having Been Returned To From A Second Userform

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,564
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have a userform (uf1_assess_sched) with a listbox (uf1_listbox3).
When the user selects an item in uf1_listbox3, a second userform (group_1) is opened.

The user has a commandbutton (exit1) he may push to exit group_1. Upon exiting group_1, the user may once again select a value from uf1_listbox3 to continue the process again.

However, after the user exits from group_1 (see code below), and uf1_assess_sched returns to focus, none of the controls (listboxes) on that userform appear to trigger. ie, if the user selects an item in uf1_listbox3 nothing happens. The uf1_listbox3 click event (see code below) is not executed. Please help to regain this functionality.

uf1_listbox3 CLICK event ... opens up userform group_1 once an iten in uf1_listbox3 has been selected
Code:
Private Sub uf1_listbox3_Click()
    If mbEvents Then Exit Sub
    MsgBox Me.uf1_listbox3.Value
    group_1.Show
End Sub

From userform_1, the user is returned to uf1_assess_sched having pushed the exit (exit1) button
Code:
Private Sub exit1_Click()
    
    Dim ui2 As VbMsgBoxResult
    Dim lastrow As Long
    
    If ws_vh.Range("E2") > 0 Then 'unsaved info
        Me.Label34.Caption = "    Saving unsaved rental data."
        Me.Label34.BorderColor = RGB(50, 205, 50)
        lastrow = ws_rd.Cells(ws_rd.Rows.Count, "A").End(xlUp).Row
        ws_rd.Range("A3:FZ" & lastrow).Sort key1:=ws_rd.Range("A3"), order1:=xlAscending, Header:=xlNo
        Application.DisplayAlerts = False
        ThisWorkbook.Save
        Application.DisplayAlerts = True
        Unload group_1
        End
    End If
    
    If ws_vh.Range("B2") > 0 Then   'Outstanding rentals?
        ui2 = MsgBox("You still have " & ws_vh.Range("C2") & " rentals with critical missing rental information." & Chr(13) & Chr(13) _
            & "Active (Sports) rentals: " & ws_vh.Range("B3") & Chr(13) & "Passive (Picnics) rentals: " & ws_vh.Range("B4") & Chr(13) & Chr(13) _
            & "Are you sure you wish to exit?", vbInformation + vbYesNo, "OUTSTANDING RENTAL INFORMATION")
        If ui2 = vbYes Then
            If ws_vh.Range("N4") > 0 Then
                Me.Label34.Caption = "    Saving unsaved rental data."
                Me.Label34.BorderColor = RGB(50, 205, 50)
                lastrow = ws_rd.Cells(ws_rd.Rows.Count, "A").End(xlUp).Row
                ws_rd.Range("A3:FZ" & lastrow).Sort key1:=ws_rd.Range("A3"), order1:=xlAscending, Header:=xlNo
                Application.DisplayAlerts = False
                ThisWorkbook.Save
                Application.DisplayAlerts = True
                Unload group_1
                With uf1_assess_sched
                    .uf1_listbox3.ListIndex = -1
                End With
                Exit Sub
            Else
                Unload Me
                End
            End If
        Else
            Exit Sub
        End If
     End If

    Unload group_1
    End

End Sub

I would be very grateful for any assistance in diagnosing and resolving this problem.
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
I suspect it is due to the mbEvents Boolean that is set to True somewhere

Also, bear in mind that using the End Statement releases all variables and is a very bad practice ... that's probably why you are having this problem
 
Last edited:
Upvote 0
Hi Jaafar, thank you for your reply. It's much appreciated.

I had suspected mbEvents as the possible culprit, so I added a watch for it. Now, it could be I set up the watch improperly, but it never reported anything, true or false, while running through this code. I suppose I could do an immediate to see what it is at the point group_1 is closed.

I did not know the consequences of using the End statement. With this I will avoid using it. What is a better option if I may ask?
 
Upvote 0
Hi Mike ... unload.

Code:
Unload group_1
 
Upvote 0
So, I'm feeling confident that my problem may be resolved with Jaafar's advice.

I have substituted "End" with "Exit Sub". I anticipate some problems down the road, as at one point ending was the only way I was able to stop the code from previous modules from continuing. Bad planning / coding I suppose.
I have added mbEvents=False prior to unloading group_1. That seems to have been the problem.

Thanks all!!

The issue I am having now, is I'm unable to deselect the item the user had initially selected upon returning to uf1_assess_sched. I believe that may have been part of the problem as their was only one item in the listbox. It was selected initially, and remained selected (highlighted) upon return. It was unable to be re-selected to trigger the code, giving the impression the click trigger was failing.

I had these lines in my original code hoping it would work. It appears it doesn't. Any suggestions why?

Code:
Unload group_1
With uf1_assess_sched
    .uf1_listbox3.ListIndex = -1
End With
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,381
Messages
6,124,614
Members
449,175
Latest member
Anniewonder

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