Can an add-in run code automatically when loaded? (1 Viewer)

burma

Member
Local time
Today, 02:16
Joined
Jan 17, 2024
Messages
50
I have an Access file that does one thing when it opens: it displays the message "hello". I then install the file as an add-in. When I open another Access file, let's call it Add-in Test A.accdb, the add-in is there in the Add-ins menu but the "hello" message doesn't display unless I click it from the Add-ins menu. Is there a way to make it so the Add-in will display the message automatically when I open any Access file, not just Add-in Test A.accdb? Thx
 

theDBguy

I’m here to help
Staff member
Local time
Today, 02:16
Joined
Oct 29, 2018
Messages
21,473
Can you add an autoexec macro in the new db and call the code in the add in?
 

burma

Member
Local time
Today, 02:16
Joined
Jan 17, 2024
Messages
50
Can you add an autoexec macro in the new db and call the code in the add in?
Tried that but no dice: the msgbox doesn't fire unless I click the add-in from the Add-ins menu.
 

Josef P.

Well-known member
Local time
Today, 11:16
Joined
Feb 2, 2023
Messages
826
the add-in is there in the Add-ins menu but the "hello" message doesn't display unless I click it from the Add-ins menu
If this is an Access add-in, it is only loaded when you start it from the add-in menu or via another call.
Only the presence in the add-in menu cannot start a code.
 

isladogs

MVP / VIP
Local time
Today, 10:16
Joined
Jan 14, 2017
Messages
18,224
I may be wrong but I think Access add-ins cannot start automatically. They do have to be loaded each time you need them.
If you only use the add-in to run code, then an alternative is to add the file as a library reference and that will be loaded automatically at startup. However, doing that won't allow you to open forms from the add-in file.
 

burma

Member
Local time
Today, 02:16
Joined
Jan 17, 2024
Messages
50
I may be wrong but I think Access add-ins cannot start automatically. They do have to be loaded each time you need them.
If you only use the add-in to run code, then an alternative is to add the file as a library reference and that will be loaded automatically at startup. However, doing that won't allow you to open forms from the add-in file.
So are you talking about a COM add-in? Perhaps having two add-ins: a COM add-in and an Access add-in. But the goal is to start automatically, and run code. Maybe I would want to open forms in a later version. The other goal is Ribbons that would only show when the add-in is started.
 

isladogs

MVP / VIP
Local time
Today, 10:16
Joined
Jan 14, 2017
Messages
18,224
I was referring to 'standard' Access add-ins.
COM add-ins are totally different and can start automatically but I have no experience of creating those.
 

Josef P.

Well-known member
Local time
Today, 11:16
Joined
Feb 2, 2023
Messages
826
If you are using a COM add-in, IDTExtensibility2 and IRibbonExtensibility are available as interfaces.


The other goal is Ribbons that would only show when the add-in is started.
This should also be possible with an Access add-in.
You write above that the add-in should be loaded automatically. - This is not possible with an Access add-in.

How should the add-in be started?
  • Per user activity (click on button in the application, application ribbon or in the add-in menu, ...)
  • When a specific application/database is loaded
  • When any database file is loaded
  • When Access is started
If I understood #1 correctly, it should be one of the last 2 points. => COM-Add-In
 
Last edited:

burma

Member
Local time
Today, 02:16
Joined
Jan 17, 2024
Messages
50
You write above that the add-in should be loaded automatically. - This is not possible with an Access add-in.
Can an Access add-in be loaded from a COM add-in?

How should the add-in be started?
  • Per user activity (click on button in the application, application ribbon or in the add-in menu, ...)
  • When a specific application/database is loaded
  • When any database file is loaded
  • When Access is started
If I understood #1 correctly, it should be one of the last 2 points. => COM-Add-In
Yes, the last two. Or at least: when any database file is loaded. Thx
 
Last edited:

Josef P.

Well-known member
Local time
Today, 11:16
Joined
Feb 2, 2023
Messages
826
Can an Access add-in be loaded from a COM add-in?
Yes, if an Access.Application object is available.
AccessApplicationReference.Run "PathToAddinAccdaWithoutFileExt.AddInFunktion"
 

burma

Member
Local time
Today, 02:16
Joined
Jan 17, 2024
Messages
50
Yes, if an Access.Application object is available.
AccessApplicationReference.Run "PathToAddinAccdaWithoutFileExt.AddInFunktion"
So, assuming the Access.Application object is available, I can kick off the the Access add-in from COM. The only thing I would need the COM add-in for is to load the Access add-in. The rest of the code would run from the Access add-in presumably. Sound doable?
 

AHeyne

Registered User.
Local time
Today, 11:16
Joined
Jan 27, 2006
Messages
92
Just for info: You can create a COM add-in quite easy with twinBASIC (compared to .NET or other solutions):
 

Josef P.

Well-known member
Local time
Today, 11:16
Joined
Feb 2, 2023
Messages
826
A simple example:
This COM add-in does nothing other than provide a ribbon to start various access add-ins from the ribbon.
The add-in was created with twinBasic, but it is not much different with C# either.
 

burma

Member
Local time
Today, 02:16
Joined
Jan 17, 2024
Messages
50
Just for info: You can create a COM add-in quite easy with twinBASIC (compared to .NET or other solutions):
Thanks - I've read about twinBASIC. is there a free version?
 

AHeyne

Registered User.
Local time
Today, 11:16
Joined
Jan 27, 2006
Messages
92
Yes. Both, 32-bit and 64-bit versions are free. But 64-bit shows a 5 second nag screen.
 

burma

Member
Local time
Today, 02:16
Joined
Jan 17, 2024
Messages
50
A simple example:
This COM add-in does nothing other than provide a ribbon to start various access add-ins from the ribbon.
The add-in was created with twinBasic, but it is not much different with C# either.
Except, I need a COM add-in to actually load the Access add-in, not just provide a ribbon. Thx
 

Users who are viewing this thread

Top Bottom