Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4022628
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:29:56+00:00 2026-05-20T10:29:56+00:00

I want to embed a simple piece of VBA Code in Access 2007. I

  • 0

I want to embed a simple piece of VBA Code in Access 2007. I need to execute this code on hundreds of different Access DBs, so I don’t want to manually paste the code into each and every DB. Is it possible to do this? Maybe by way of an add-in?

Thanks
Karl

EDIT

I want to execute the following VBA code:

DoCmd.DeleteObject acTable, "LastNum"
DoCmd.TransferDatabase acLink, "ODBC Database", "ODBC;DSN=myDB;UID=User1;PWD=123;LANGUAGE=u s_english;" & "DATABASE=LastNumber", acTable, "LastNum", "LastNum"

How would I translate this into a VB addin?

The visual studio VB add-in template looks like this:

imports Extensibility
imports System.Runtime.InteropServices

<GuidAttribute("B61E2444-F46E-4591-A8BA-3D06A4E5D84C"), ProgIdAttribute("MyAddin1.Connect")> _
Public Class Connect

    Implements Extensibility.IDTExtensibility2

    Private applicationObject As Object
        Private addInInstance As Object

    Public Sub OnBeginShutdown(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnBeginShutdown
    End Sub

    Public Sub OnAddInsUpdate(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnAddInsUpdate
    End Sub

    Public Sub OnStartupComplete(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnStartupComplete
    End Sub

    Public Sub OnDisconnection(ByVal RemoveMode As Extensibility.ext_DisconnectMode, ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnDisconnection
    End Sub

    Public Sub OnConnection(ByVal application As Object, ByVal connectMode As Extensibility.ext_ConnectMode, ByVal addInInst As Object, ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnConnection
        applicationObject = application
        addInInstance = addInInst

    End Sub

End Class

EDIT PART 2:

Ok, so I figured out I should do the following:

imports Extensibility
Imports System.Runtime.InteropServices
Imports Microsoft.Office.Core
Imports Access = Microsoft.Office.Interop.Access



<GuidAttribute("B61E2444-F46E-4591-A8BA-3D06A4E5D84C"), ProgIdAttribute("MyAddin1.Connect")> _
Public Class Connect

    Implements Extensibility.IDTExtensibility2

    Private applicationObject As Access.Application
    Private addInInstance As Microsoft.Office.Core.COMAddIn


    Public Sub OnBeginShutdown(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnBeginShutdown
    End Sub

    Public Sub OnAddInsUpdate(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnAddInsUpdate
    End Sub

    Public Sub OnStartupComplete(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnStartupComplete
    End Sub

    Public Sub OnDisconnection(ByVal RemoveMode As Extensibility.ext_DisconnectMode, ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnDisconnection
    End Sub

    Public Sub OnConnection(ByVal application As Object, ByVal connectMode As Extensibility.ext_ConnectMode, ByVal addInInst As Object, ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnConnection

        applicationObject = CType(application, Access.Application)
        addInInstance = CType(addInInst, Microsoft.Office.Core.COMAddIn)

        ' This line enables VBA to call back into this object.
        addInInstance.Object = Me


    End Sub

    Public Sub ChangeLink()

        applicationObject.DoCmd.DeleteObject(Access.AcObjectType.acTable, "LastPolNum")
        applicationObject.DoCmd.TransferDatabase(Access.AcDataTransferType.acLink, "ODBC Database", "ODBC;DSN=ZACANTDB02;UID=EDIPolicyNumber;PWD=museum123;LANGUAGE=u s_english;" & "DATABASE=EDIPolicyNumber", Access.AcObjectType.acTable, "LastPolnum", "LastPolNum")

    End Sub

End Class

Now what I want is to be able to execute ChangeLink() from Access. How do I do that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T10:29:57+00:00Added an answer on May 20, 2026 at 10:29 am

    Depending on what the code is for, there are (at least) two different ways to do this, without working at the VB Extensions level (which is where you’d copy and paste code, at least in VBA):

    1. Make the code part of an add-in. It can then be loaded, and stay loaded and exposed, to any other application.

    2. If the code is working on data only, consider writing a procedure that links and unlinks the table(s) in each mdb file that needs processing.

    The advantage of #2 over #1 (and, indeed, over copying and pasting code) is that you can invoke your simple routine once, not hundreds of times.


    EDIT:

    There are two ways to invoke an add-in, depending on who is meant to invoke its functionality, and how.

    1. Through the UI. Use this when you want an end user to be able to use it, especially practical for functionality you’ll invoke often. How to:
      a. Office button > Access options > Add-ins tab
      b. If it’s a .NET add-in (or any other non-Access add-in), choose COM Add-in from Manage dropdown. If it’s Access, choose Access. Click go
      c. Click Add button in the form that pops up, browse to the add-in.

    You will still need to provide some sort of UI to it: a commandbar, a ribbon button, a form, something. That’s a separate discussion

    1. Through code. Use this if you’re just wanting to invoke it as part of some other VBA procedure.
      a. VBE window > Tools > References
      b. Browse button
      c. Change the dropdown in file of type if you’re setting up an Access add-in.

    You can then call the line of code directly, as if it were part of your current project. If you wish to be more explicit, you can also invoke it by library name: MyAddInName.ChangeLink

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to embed a wikipedia article into a page but I don't want
I want to Embed SVG into XUL. I tried to use the this tutorial
I have a script that gets embed code for me.I am using php simple
I have a simple java application and want to embed it into a jsp
I want to provide a simple piece of Javascript (or an iframe, I guess)
I want to embed an .asp page on an html page. I cannot use
I want to embed Javascript in a hobby game engine of mine. Now that
I want to embed a link to a controller action in my page so
I want to embed the native camera application into custom form. The RECT r
I want to embed a dsl or existing full language within my application. It

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.