Note that there are some explanatory texts on larger screens.

plurals
  1. POVBA: WithEvents puzzle
    primarykey
    data
    text
    <p>I have a UserForm, <strong>xForm</strong>, that is being instantiated in a class module (let's say <strong>TestClass</strong>) as:</p> <pre><code>'TestClass Dim Form as New xForm Private WithEvents EvForm as MSForms.UserForm Set EvForm = Form </code></pre> <p>At the class module of the xForm itself I have some code that must be executed on Form Closing, ONLY if the form actually closes:</p> <pre><code>'xForm class module Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer) 'Do some cleanup, otherwise the app would hang 'If not closing, don't cleanup anything, otherwise the app would hang End Sub </code></pre> <p>The QueryClose event is also treated in TestClass, and could avoid the form from closing:</p> <pre><code>'TestClass Private Sub EvForm_QueryClose(Cancel As Integer, CloseMode As Integer) 'Verify if closing is allowed based on User Control values Cancel = Not ClosingIsAllowed '&lt;-- Pseudocode on the right side of "=" End Sub </code></pre> <p>How can I test for Cancel = True, set in TestClass, in the xForm class module? Let's rephrase it: If Cancel is set to True in TestClass, I must not do the cleanup code in the xForm class module. How can I accomplish that?</p> <p>Until now, I have thought off of implementing another event in the xForm class (My_QueryClose?) and raise it on the QueryClose event. Outside the Code Behind Form I would deal only with the My_QueryClose event, so taking full control over what is happening. Is this a viable/better approach?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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