sunyem
New Member
- Joined
- Jun 28, 2017
- Messages
- 14
Hello Everyone,
I am trying to create a sub (BOX_TYPE)that opens a userform. Since this is a step in a series of subs, I wanted to add the option of confirming closing the userform in the event of clicking on the close button (top right [X]). I manged it using this code:
Now as you can see, if someone clicks "No" then it returns to the original sub which is very basic:
The problem is, when it opens the userform for the second time, it becomes insensitive of clicking on the close button and I am not sure why. I tried unloading the form as well using this code (in which case, I - of course - linked the userform to this sub instead of BOX_TYPE):
Eventually it did not work, so can someone please explain me, what went wrong?
Thank you!
I am trying to create a sub (BOX_TYPE)that opens a userform. Since this is a step in a series of subs, I wanted to add the option of confirming closing the userform in the event of clicking on the close button (top right [X]). I manged it using this code:
Code:
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
Dim WantTo As VbMsgBoxResult
If CloseMode = vbFormControlMenu Then
WantTo = MsgBox("Do you want to quit?", vbYesNo)
If WantTo = vbYes Then
UserForm1.Hide
Exit Sub
Else
UserForm1.Hide
BOX_TYPE
End If
Else
End If
End Sub
Now as you can see, if someone clicks "No" then it returns to the original sub which is very basic:
Code:
Sub BOX_TYPE()
MsgBox "Please select the TYPE and PERIOD of the account"
UserForm1.Show
End Sub
The problem is, when it opens the userform for the second time, it becomes insensitive of clicking on the close button and I am not sure why. I tried unloading the form as well using this code (in which case, I - of course - linked the userform to this sub instead of BOX_TYPE):
Code:
Sub CLOSE_USER_FORMS()
Dim i As Long
Dim UFName As String
For i = VBA.UserForms.Count - 1 To 0 Step -1
UFName = Str & VBA.UserForms(i).Name
Unload VBA.UserForms(i)
Next i
MsgBox UFName & "unloaded"
BOX_TYPE
End Sub
Eventually it did not work, so can someone please explain me, what went wrong?
Thank you!