Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Can't make heads or tails of your custom event idea, but the way to get one class to talk to another (form or anything else, doesn't matter) is to link them up; here's a clean example:</p> <p>Basic TestClass holds form object (no events needed here, let the form handle that)</p> <pre><code>'TestClass code Private MyForm As UserForm Private mbleCanClose As Boolean Public Property Get CanClose() As Boolean CanClose = mbleCanClose End Property Public Property Let CanClose(pbleCanClose As Boolean) mbleCanClose = pbleCanClose End Property Public Property Get MyFormProp() As UserForm1 Set MyFormProp = MyForm End Property </code></pre> <p>Add a custom object and property to the form itself</p> <pre><code>'UserForm1 code Private mParent As TestClass Public Property Get Parent() As TestClass Set Parent = mParent End Property Public Property Set Parent(pParent As TestClass) Set mParent = pParent End Property </code></pre> <p>Invoking the form on TestClass creation looks like this:</p> <pre><code>'TestClass code Private Sub Class_Initialize() Set MyForm = New UserForm1 Load MyForm Set MyForm.Parent = Me End Sub </code></pre> <p>And then when it's time to close the form, you check whether you can:</p> <pre><code>'UserForm1 code Public Function WillMyParentLetMeClose() As Boolean If Not (mParent Is Nothing) Then WillMyParentLetMeClose = mParent.CanClose End If End Function Private Sub CommandButton1_Click() If WillMyParentLetMeClose = True Then Unload Me End If End Sub </code></pre> <p>Here's what it would like to invoke</p> <pre><code>'standard module code Public Sub Test_TestClass() Dim myclass As TestClass Set myclass = New TestClass myclass.MyFormProp.Show End Sub </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