Access 2007 / VBA - Multiple Instances of Form, Up

2019-08-24 17:37发布

I am using Allen Browne's method for creating and managing multiple instances of a form. I am stuck on how to reference controls or properties on a specific instance of the form from a VBA Module. Here is how I open a new instance:

'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

Assume I have three instances of the frmMasterRecord open. How do I call a sub/function in a Module and have it manipulate controls only on the calling instance of the form?

1条回答
地球回转人心会变
2楼-- · 2019-08-24 18:12

Pass a reference to the calling form:

Result = MyExternalFunction(Me)

and

Public Function MyExternalFunction(ByRef frm As Form) As Boolean

    ' Do stuff with object frm.

    MyExternalFunction = Result

End Function
查看更多
登录 后发表回答