Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>A work around declaring another event</strong></p> <p>The code bellow do what I was expecting, although it is not as neat as I wish it could be.</p> <p>In the <strong>UserForm1</strong> code:</p> <pre><code>'***** UserForm1 Public Event MyQueryClose(ByRef Cancel As Integer, ByRef CloseMode As Integer, ByRef Status As String) Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer) Dim Status As String Cancel = True Status = "QueryClose" Debug.Print "Entered QueryClose" Debug.Print "Cancel = " &amp; Cancel Debug.Print "Status = " &amp; Status Debug.Print "Just before raising MyQueryClose" RaiseEvent MyQueryClose(Cancel, CloseMode, Status) Debug.Print "Just got back from MyQueryClose" Debug.Print "Cancel = " &amp; Cancel Debug.Print "Status = " &amp; Status End Sub </code></pre> <p>In the <strong>Class1</strong> code:</p> <pre><code>'***** Class1 Dim UserForm As New UserForm1 Private WithEvents UF As UserForm1 Sub DoIt() Set UF = UserForm UserForm.Show End Sub Private Sub UF_MyQueryClose(Cancel As Integer, CloseMode As Integer, Status As String) Debug.Print "Just entered MyQueryClose" Cancel = False Status = "MY QueryClose" End Sub </code></pre> <p>In a <strong>basic module</strong>, to test the Class:</p> <pre><code>'***** Basic module Sub TestClass() Dim C As New Class1 C.DoIt End Sub </code></pre> <p>And here's the end result (debug window):</p> <pre><code>TestClass Entered QueryClose Cancel = -1 Status = QueryClose Just before raising MyQueryClose Just entered MyQueryClose Just got back from MyQueryClose Cancel = 0 Status = MY QueryClose </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload