Hello, everyone. I'm an Access programmer living in Japan.
Please forgive me if my English grammar is a bit strange.
I suspect that the title is impossible for the following reasons.
<caller.accdb>
formA
<reference.accdb>
formB (2 CommandButtons and subForm Control)
moduleB (show formB)
Please let me know if you know a better way. Thank you in advance.
Please forgive me if my English grammar is a bit strange.
I suspect that the title is impossible for the following reasons.
- It is possible to pass an instance of the source form to the referent and display it in the referent.
- However, the only thing that can be set in the SourceObject is the string form name. And that it can only be set to your own form object.
<caller.accdb>
formA
<reference.accdb>
formB (2 CommandButtons and subForm Control)
moduleB (show formB)
Code:
'1st VBA reference setting, caller.accdb --> reference.accdb
'2nd run with immediate window in caller.accdb VBA
Call moduleB.ShowFormB(New Form_formA)
Code:
'moduleB
Option Compare Database
Option Explicit
Public gTargetFormA As Form 'refer from formB
Public Sub ShowFormB(ByRef targetFormA As Form)
Set gTargetFormA = targetFormA
DoCmd.openForm "formB"
End Sub
Code:
'formB
Option Compare Database
Option Explicit
Private Sub cmdTestSubForm_Click()
Debug.Print "caller form name:" & gTargetFormA.NAME ' "formA"
Me.subForm.SourceObject = gTargetFormA.NAME ' error 2101
End Sub
Private Sub cmdTestDisplayCallerForm_Click()
Debug.Print "caller form name:" & gTargetFormA.NAME ' "formA"
gTargetFormA.Visible = True ' ok
End Sub
Please let me know if you know a better way. Thank you in advance.