Using add-in with internal databases. (1 Viewer)

jackyP

New member
Local time
Today, 07:52
Joined
Sep 26, 2023
Messages
27
Thank you very much for your suggestions.
Now I just have to make these changes.
Thank you very much for your suggestions.
Now I just have to make these changes.
When opening the add-in, I create the tables in the calling application and define the links to these tables in my add-in. This works perfectly with a single calling application.
For a second calling application, I perform the same task.
The problem is that the table links to the second calling application overwrite the table links of the first application.
 

Josef P.

Well-known member
Local time
Today, 07:52
Joined
Feb 2, 2023
Messages
826
Do not use linked tables but bind the forms to a recordset at runtime or use a SQL statement including the connection string.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 00:52
Joined
Feb 28, 2001
Messages
27,186
I found that internal databases were common to all open add-ins.
The problem is that the table links to the second calling application overwrite the table links of the first application.

I'm coming to this late. I will have to be careful with nomenclature here because casual references might be confusing.

When you log in, you create several things including a SESSION (which is a resource accounting entity) and a task (or more precisely, a process within a task). You absolutely CAN open multiple tasks in a session. I.e. spawning tasks on your desktop such as opening Word and Excel side-by-side (neither one maximized) with the Desktop still open behind both programs.

If you did that and poked around with Windows Task Manager, you would see several processes, each with a unique process ID. If you have a program that is capable of multi-threading, each thread - when active - runs in the context of a unique process. The process terminates when the thread terminates. Each process has its own memory and other resources. For most Windows desktop situations, you don't have user quotas, though if you were on a Windows Server implementation, you might run into per-session quotas and limits.

Here is the side-effect of what you are doing. If all of the add-ins are open in the same process (defined by having the same process ID), they are sharing the same virtual memory, too, because of Windows task isolation rules. Multi-threaded programs can share the same code and data space because a process can set up the shared-memory conditions as part of the multi-thread setup. The task can spawn a child process that can share the code with other child processes. But in the absence of a multi-thread environment inside your task, you will have a single process with a single set of resources allocated to it. This will be particularly true with Access, which was NOT written to be multi-threaded.

This means that when you open your Access database that activates this add-in, if the add-in ALSO opens an Access database, you are still in the same process and MUST - by Windows rules - share the same virtual memory space. (And same memory copy of MSACCESS.EXE.) They are part of the same process and therefore CANNOT isolate themselves from other databases that are open in the same process. The distinction is that "same SESSION" processes can operate independently for the duration of the relevant processes. They have independent memory and CPU resource allocation. But what you have described is NOT independent. It is all part of one big conglomeration.

At least part of your problem is therefore that you cannot isolate the multiple internal databases because they share the same virtual memory space. You can open a second calling application only by having ANOTHER set of qualifier variables to track the new DB different from the ones you used for the previous DB. In a sense, this is a vicious recursion problem where part of the recursion is triggered from the Add-In.
 

Josef P.

Well-known member
Local time
Today, 07:52
Joined
Feb 2, 2023
Messages
826
A simple Test-Add-In:
The add-in creates the table usys_AddInDataTable in the calling application and enables the table data to be changed via the add-in form.
 

Attachments

  • TestAddIn.zip
    32.1 KB · Views: 55

jackyP

New member
Local time
Today, 07:52
Joined
Sep 26, 2023
Messages
27
Un simple complément de test :
Le complément crée la table usys_AddInDataTable dans l'application appelante et permet de modifier les données de la table via le formulaire de complément.

A simple Test-Add-In:
The add-in creates the table usys_AddInDataTable in the calling application and enables the table data to be changed via the add-in form.

Hi @Josef P.

Thank you for your testing program.
For your information, we can replace the subroutine in the subform with:
Code:
Public Sub SetData(ByVal SourceDb As String)

Me.RecordSource = "SELECT * FROM " & AddInTableName & "IN '" & SourceDb & "'"

End Sub

Another question :
What should I do with queries that were created in the add-in from the Querry tools Tab?
These tables are now in the calling program without a link to the add-in.

Do we have to recreate them by code in VBA with the connection to the calling program or is there a way in Design mode to define the connection?
 

ebs17

Well-known member
Local time
Today, 07:52
Joined
Feb 7, 2020
Messages
1,946
A stored named query is a database object.
Code:
Dim qd As DAO.QueryDef
Debug.Print CodeDb.Name
For Each qd in CodeDb.QueryDefs
   Debug.Print qd.Name
   Debug.Print qd.SQL
Next
Debug.Print CurrentDb.Name
For Each qd in CurrentDb.QueryDefs
   Debug.Print qd.Name
   Debug.Print qd.SQL
Next

' for action queries
CurrentDb.Execute "QueryX", dbFailOnError
Code.Execute "QueryY", dbFailOnError
 

Josef P.

Well-known member
Local time
Today, 07:52
Joined
Feb 2, 2023
Messages
826
For your information, we can replace the subroutine in the subform with: ...
Yes, that is also possible. Just like select ..from [Connectionstring].Table ...
However, I don't see any advantage compared to the recordset variant.

What should I do with queries that were created in the add-in from the Querry tools Tab?
I would avoid any stored add-in database object that provides data to the application.
Can't you just use the SQL statement from it with the appropriate DAO.Database reference (CurrentDB)?
 

Users who are viewing this thread

Top Bottom