Terminate all procedures?

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,564
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
At a point in my userform initialization, I call a routine that checks for missing information that is critical to the userform initialization continuing.

uf_create_wo2 initialization
Rich (BB code):
Private Sub UserForm_Initialize()
    ... some code
    missing_rental_info ws_rd, norec 'lng_miss_rtl  '[module 21]
            
    For i = 2 To norec + 1
    ... some code
End Sub

missing_rental_info
Rich (BB code):
Sub missing_rental_info(ByVal ws_rd As Worksheet, ByVal norec As Long) ', ByVal lng_miss_rtl As Long
        
    Dim i As Double
    Dim ui2 As VbMsgBoxResult
    Dim ws_core As Worksheet
    Dim ws_vh As Worksheet
    Dim fn As String
    Dim mr_cnt As Integer
    
    fn = Workbooks("Sports15b.xlsm").Worksheets("VAR_HOLD").Range("B4")
    MsgBox fn
    Set ws_core = Workbooks(fn).Worksheets("CORE")
    Set ws_vh = Workbooks("Sports15b.xlsm").Worksheets("VAR_HOLD")
    
    With ws_vh
        .Range("J5") = 0
        .Range("K5:K105").Cells.ClearContents
    End With
        
    With ws_core
        lng_miss_rtl = 0
        For i = 2 To norec
            If IsError(Application.Match(.Range("C" & i), ws_rd.Range("A:A"), 0)) Then
                mr_cnt = mr_cnt + 1
                With ws_vh
                    .Range("J5") = mr_cnt
                    .Range("K" & mr_cnt + 4) = ws_core.Range("C" & i).Value
                End With
            End If
        Next i
    End With
        
    If mr_cnt > 0 Then
        ui2 = MsgBox(mr_cnt & " record(s) were encountered that are not in the rental database." & Chr(13) & Chr(13) & "To proceed, you must submit this missing rental information to the database." _
            & Chr(13) & Chr(13) & "Do you wish to do this now?", vbCritical + vbYesNo, "CRITICAL ERROR")
        If ui2 = vbYes Then
            Workbooks(fn).Close False
            group_1.Show
        Else
            Workbooks(fn).Close False
            Worksheets("DYNAMIC").Activate
            Unload uf_create_wo2
        End If
    End If
End Sub

The above procedure compiles a list of missing unique rental numbers from the source data. As long as there are missing rental numbers, userform uf_create_wo2 must not continue. This procedure allows the user to access another module (which can be used outside of this calling to enter information outside of error checking) to enter information pertaining to the missing rentals by calling userform group_1 ... a userform whose purpose is to process rental number information.

The group_1 initialization code uses the information compiled in the procedure above. There is an "EXIT" commandbutton (exit1) in userform group_1 allowing users to exit the process. If the user chooses to exit while there is still unprocessed rental information, the user is prompted to confirm the action of quitting prematurely.

exit1
Rich (BB code):
Private Sub exit1_Click()
    
    Dim ui2 As VbMsgBoxResult
    Dim ws_vh As Worksheet
    
    Set ws_vh = Workbooks("Sports15b.xlsm").Worksheets("VAR_HOLD")
    
    If ws_vh.Range("J5") > 0 Then
        ui2 = MsgBox("You still have outstanding missing rental information." & Chr(13) & "Are you sure you wish to exit?", vbInformation + vbYesNo, "OUTSTANDING RENTAL INFORMATION")
        If ui2 = vbYes Then
            Unload uf_create_wo2
            Worksheets("DYNAMIC").Activate
            Unload Me
            Exit Sub
        Else
            Exit Sub
        End If
    Else
        Unload Me
    End If
End Sub

If "YES", it is hoped to close any further code, returning the user to the main launch worksheet ("DYNAMIC"). In the most part it's doing so with the code I've experimented with thus far.

The issue ... the code eventually returns to the original userform uf_create_wo2 initialization in the line in green above. This is not good, as all kinds of problems related to missing information results.

What do I need to do to exit everything completely when the user chooses yes to abandoning critical information entry and preventing userform initialization from resuming?
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
At a point in my userform initialization, I call a routine that checks for missing information that is critical to the userform initialization continuing.



The issue ... the code eventually returns to the original userform uf_create_wo2 initialization in the line in green above. This is not good, as all kinds of problems related to missing information results.

What do I need to do to exit everything completely when the user chooses yes to abandoning critical information entry and preventing userform initialization from resuming?
You could probably use the 'End' statement. But I would make a back-up copy of my file before trying that, just in case. According to the description of the statement, it stops everything cold and closes the file. I have never used it, but have seen posts where it has been successfully used when 'Stop' or 'Quit' were not what the user wanted. You can review the description yourself in VBA help file by opening the VB editor, click the help button, click on vb language reference then type 'End Statement' in the search box. It also has an example of code there.
 
Last edited:
Upvote 0
Wow! I spent good time writing my post to provide as much clear information I could for such as simple solution. Who would have guessed ... a single 3 letter word.
Thank you JLGWhiz, seems to be what I was looking for.
 
Upvote 0
Wow! I spent good time writing my post to provide as much clear information I could for such as simple solution. Who would have guessed ... a single 3 letter word.
Thank you JLGWhiz, seems to be what I was looking for.

Happy to help,
Regards, JLG
 
Upvote 0

Forum statistics

Threads
1,215,156
Messages
6,123,338
Members
449,098
Latest member
thnirmitha

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