Unload UserForm Continues Sub

breynolds0431

Active Member
Joined
Feb 15, 2013
Messages
303
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have a userform (ufRandom) that will show a disclaimer message, which is another userform titled ufDisclaimer, after the user clicks a combo button to import a sheet from an external workbook. The import process uses the File Picker to allow the user to select the file they need imported. The ufDisclaimer has two combo button options to Continue and Cancel. In the Cancel_Click(), I have it first Unloading Me and then Unloading ufRandom. Both userforms successfully unload, but the File Picker still subsequently displays.

Here is what I have in ufDisclaimer:

VBA Code:
Private Sub cbCancel_Click()
     Unload Me
     Unload ufRandom
End Sub

So I tried adding an IF to ufRandom to exit if ufDisclaimer's Cancel button was clicked. That didn't stop the File Picker from displaying either. Below is the piece from ufRandom that is supposed to exit if the Cancel button was clicked.

Code:
Private Sub Import_Click()

'declarations here

ufDisclaimer.Show

If ufDisclaimer.cbCancel = True Then
     Exit Sub
End If

'rest of code here

End Sub

Any ideas on how to exit the whole operation with the ufDisclaimer Cancel button?
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Hi,
place following codes in your ufDisclaimer code page


Rich (BB code):
Function Response() As VbMsgBoxResult
    Me.Show
    Response = Val(Me.Tag)
End Function

Private Sub cmdCancel_Click()
    Me.Tag = vbCancel
    Me.Hide
End Sub

Private Sub cmdContinue_Click()
    Me.Tag = vbYes
    Me.Hide
End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    'X pressed
    Cancel = CloseMode = 0
    If Cancel Then Call cmdCancel_Click
End Sub

Change the commandbutton names shown in BOLD as required


To call the code

VBA Code:
Private Sub Import_Click()

'declarations here

    If ufDisclaimer.Response = vbCancel Then
   
         Exit Sub
        
    Else
   
        'rest of code here
       
        MsgBox "Show File Picker"
   
   
    End If

End Sub

Dave
 
Upvote 0
Solution
Opps sorry, omitted a line code – add line shown in BOLD

Rich (BB code):
Function Response() As VbMsgBoxResult
    Me.Show
    Response = Val(Me.Tag)
    Unload Me
End Function

Dave
 
Upvote 0
Opps sorry, omitted a line code – add line shown in BOLD

Rich (BB code):
Function Response() As VbMsgBoxResult
    Me.Show
    Response = Val(Me.Tag)
    Unload Me
End Function

Dave

Thank you, Dave! Works great.
 
Upvote 0

Forum statistics

Threads
1,214,952
Messages
6,122,457
Members
449,083
Latest member
Ava19

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