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

nario

New member
Local time
Today, 13:05
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.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 00:05
Joined
May 21, 2018
Messages
5,406
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.
 

nario

New member
Local time
Today, 13:05
Joined
Apr 28, 2021
Messages
3
@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

Super Moderator
Staff member
Local time
Today, 00:05
Joined
Feb 19, 2002
Messages
32,908
If you are unhappy with the efficiency of Access, perhaps you are using the wrong tool or perhaps you don't understand how Access works. If you use Access the way it was designed to be used, it is plenty efficient. It is probably one of the best development tools available which explains why it is still alive and well after nearly 30 years. You can develop professional grade applications with hundreds or even thousands of users (assuming you use SQL Server for the BE. The concurrent user count is limited by your seat licenses.) in a tenth of the time a similar app can be developed using web tools. If you don't use bound forms and you attempt to impose your will on Access because you don't like the way it works, you will make yourself even more unhappy with Access and dramatically increase the amount of work you have to do. Access is a RAD (Rapid Application Development Tool) It HAS a framework. That is the whole point and is what makes Access a RAD tool. To understand what Access is doing for you is to love it. Having been a developer long before I found Access, I KNOW what Access is doing for me and I'm willing to work with its quirks in exchange for what it does behind the scenes that I no longer have to do. I've written my million lines of code and I don't need the practice. If I wanted to develop with a platform that allowed me to twiddle bits and control absolutely everything, I would use a different tool.

Access is a niche product. It is for developing data centric applications that run on a LAN. It doesn't create web pages. It has poor graphic support. It doesn't have complex financial functions (although you can find libraries to use). It no longer has a good graphing tool built in but you can automate Excel if you need charts. An Access app is contained within an .accdb file and so it is not compiled. It is interpreted which will make it slower than a compiled program. Access is 100% dependent on Jet (.mdb) or ACE (.accdb) as a container for its objects (forms/reports, etc) But the power of Access is the ability to use ODBC to use any RDBMS with ODBC support as its data store and that is what allows you to develop apps with hundreds or thousands of concurrent users. The FE database is distributed to each user so the FE is NEVER shared and the BE is SQL Server or Oracle or DB2 or whatever RDBMS your IT department prefers. The biggest constraint for Access development is that it is awkward to have multiple concurrent developers even when you have a source control product given that there is no way to share the FE between multiple users at one time if you are using a current version of Access. That means you have to develop in your own physical copy of the FE and then have a merge procedure when you want to add your piece to the larger project..
 

nario

New member
Local time
Today, 13:05
Joined
Apr 28, 2021
Messages
3
@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.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 00:05
Joined
Feb 19, 2002
Messages
32,908
You're welcome. Be careful with API's. They may not be compatible if your app is created with 32-bit Access but you need to run it with 64-bit Access.
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 14:05
Joined
Jan 20, 2009
Messages
12,370
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

Top Bottom