我正在使用Allen Browne的方法来创建和管理表单的多个实例。我坚持如何从 VBA 模块引用表单的特定实例上的控件或属性。以下是我打开新实例的方法:
'Purpose: Open an independent instance of form frmMasterRecord.
Dim frm As Form
'Housekeeping
myFilter = Trim("" & myFilter)
'Open a new instance, show it, and set a caption.
Set frm = New Form_frmMasterRecord
frm.ServerFilter = myFilter
frm.ServerFilterByForm = True
frm.Requery
frm.Visible = True
'Append it to our collection.
clnMasterRecord.Add Item:=frm, Key:=CStr(frm.hwnd)
Set frm = Nothing
假设我打开了 frmMasterRecord 的三个实例。如何调用模块中的子/函数并让它仅在表单的调用实例上操作控件?
传递对调用表单的引用:
Result = MyExternalFunction(Me)
和
Public Function MyExternalFunction(ByRef frm As Form) As Boolean
' Do stuff with object frm.
MyExternalFunction = Result
End Function