Solved Is it possible to display the caller's form in a sub form of the form displayed in the reference's form?

nario

New member
Local time
Today, 22:32
Joined
Apr 28, 2021
Messages
3
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.
  • 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.
The following is a description of the verified code.

<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.
 
I am not sure what you are trying to do and why, but your code really does nothing. All you are doing in the long run is passing a source object name which could be done far easier by just passing the source object name as string.
If I understand you correctly the answer is this cannot be done. The subform control can only instantiate an instance within the control. You can not pass it an instance and display it. There may be a way to get the functionality you want with a different approach. Can you explain the functionality you want and why. Also your English is great.
 
@MajP

Thank you for your prompt reply.

Can you explain the functionality you want and why.

I want to increase the efficiency of Access team development, so I am creating Access files that can be referenced as a framework.
  • The way I want to use the framework is to set up references using VBA.
  • As a function of the framework, I want to display the caller's form as a sub-form of the framework management.
For the above reasons, I would like to achieve the behavior described in the title.
 
@Pat Hartman

Thank you for all the advice.I think you have a point.

However, I really wanted to solve this problem technically, so I thought a lot about it and came up with the following way to achieve it.
  • Access VBA can also use the Win32API.
  • Using SetWindowLong to create a pseudo sub form.
I think Access is such a great development tool that you don't really need to use the Win32API.
I look forward to multi-platform support, which is a recent trend in Access itself. I think this will increase the number of Access users.

This issue has been resolved.
Thank you very much for your advice.
 
You could display an instance of the calling form as a subform and set the subform's recordset to calling form's recordset.
 

Users who are viewing this thread

Back
Top Bottom