I have the following code which is supposed to load a userform, and then execute some code if the cancel button on the form isn't clicked.
Sub test()
Dim frm As Userform1
Set frm = New Userform1
frm.Show
If Not frm Is Nothing Then
Debug.Print "test"
End If
End Sub
The code for the cancel button is simply
Private Sub cmdCancel_Click()
Unload Me
End Sub
I was expecting the frm object in the first code snippet to be set back to nothing when the userform was unloaded, but apparently that's not the case as "test" is printed to the immediate window whether I click cancel or not. Is there any simple way to check if the frm-object points to a loaded userform or not?
frm
know that the the userform destroyed itself. You will get an automation error when you try to access a property of the form. You need to take care of removing the userform yourself withUnload frm
. May this article gives more insight. – Storax