1
votes

I do my development in Access 2016. I've created a custom shortcut menu (right-click menu) with VBA. In order for this VBA code to run, I have to enable the Microsoft Office 16.0 Object Library reference.

Whenever I deploy this database to PCs with older versions of Access (2013 and 2010) the database is looking for the Microsoft Office 16.0 Object Library, which does not exist. I hoped that Access would be smart enough to automatically select the appropriate Object Library for the version of Microsoft that is installed. However, it does not and the code will not run until I manually set the appropriate object library.

Is there a better way to automate this? Is there some VBA code I can implement that will find the correct library? The only solution I've come up with is setting the Object Library in an older version of Access before deploying the database to other PCs(there doesn't seem to be a problem finding newer Object libraries, only older ones.)

Thanks guys.

1
application.VBE.ActiveVBProject.References.AddFromFile("") you could use based on the version?Nathan_Sav
And I can reference the library based on GUID? Do you know where I could find the appropriate GUID or a list of GUIDs? I can't find anything in googleTj Keel

1 Answers

1
votes

It seems you've early-bound your dependency to the 16.0 type library; early-bound references are always version-specific, and you can only early-bind to one specific version.

Because you're going to need to support multiple versions, you need to switch everything over to late-binding.

You haven't provided any code, so I'll give you a hypothetical example - instead of this:

Dim foo As Library.SomeType
Set foo = New Library.SomeType
foo.DoSomething(Library.SomeEnumValue)

You need to do this (and remove the early-bound reference from your project):

Const SomeEnumValue As Long = 42 'Library.SomeEnumValue
Dim foo As Object
Set foo = CreateObject("Library.SomeType")
foo.DoSomething(SomeEnumValue)

There's no automated way to do this that I know of, however you may want to keep an eye on Rubberduck issue #1184, which aims specifically to make a refactoring tool exactly for this (full disclosure: I manage that open-source project).