views:

358

answers:

3

Hi,

In have built a couple of mda library files which I am then referencing from my main Access application (i.e. using Tools -> References from within the IDE).

Is there a way that these references can be made relative rather than absolute. The reason I am asking is so that it would make it easy to set-up on the user's computer if all three files (main application and two mda files) could simply be placed in any directory and work without having to change the references...

Thanks

A: 

To get the file path for the access application

CurrentProject.Path & "\"

Then just add the other files into the same directory and get them by name. i.e.

Dim filepath As String
filepath = CurrentProject.Path & "\name_of_file.mda"
Russ Cam
unfortunately then my code would not compile...(unless I moved to late binding I guess)
MT
ah, I understand now. I think late binding might be the way to go with this.
Russ Cam
Russ, could you explain how late binding would work with Access MDBs/MDEs? I'm unaware of how to do this.
Tony Toews
This article explains it quite well -http://www.granite.ab.ca/access/latebinding.htm it's been a while since I did anything in Access but this may work for the OP, depending on what kind of application they're building
Russ Cam
@Tony- Am I right in thinking you wrote that article?!
Russ Cam
Russ, correct, I wrote that article. Late binding works well with Excel, Word, Lotus Notes, Outlook, etc. But I'm not aware of how Access MDBs can use late binding to reference functions in other Access MDBs.
Tony Toews
@Tony- I stand corrected. I've used late binding in Excel VBA before, but not in Access. I thought that it would have been possible in versions of Access 2000+ onwards (IIRC, that was the version where changes were made to Access VBA to bring it inline with other office VBA).
Russ Cam
Russ, so far as I know, it's not possible but then sometimes folks can do some interesting tinkering and solve problems. So I was rather curious. For others reading this thread see "Late Binding in Microsoft Access" page at http://www.granite.ab.ca/access/latebinding.htm
Tony Toews
A: 

You can add VBA references through VBA itself.

Dim sFilename As String
sFilename = CurrentProject.Path & "\" & whatever.mda

Application.References.AddFromFile sFilename

Just put that in your AutoExec and that reference ought to be available for everything. Of course, you'll have to check if the reference already exists before adding it, otherwise you get an error. But that's just a matter of looping through Application.References.

Mike
If the original poster is distributing the app as an MDE/ACCDE this solution won't work as you can't update references in an MDE/ACCDE.
Tony Toews
+6  A: 

Why not just place the three MDEs in the same folder on the target system? Access should find the MDE references just fine.

Or are you using the add-in logic with the USysRegInfo table? You don't really need to do that with your own add-ins. Just with developer type add-ins such as Rick Fisher's Find and Replace.

If this isn't working for you then tell us what error messages or symptoms.

Tony Toews
awesome. I'll give his a go.
MT
Works a treat. Thanks. I had no idea that it would try to resolve the references itself in such a way.
MT
BTW you can also use the the free Auto FE Updater utilitiy at http://www.autofeupdater.com/ to make downloading any new versions relatively painless. Also note that if your main FE is an MDE and you make any changes to the referenced MDEs you must make a new FE MDE as well.
Tony Toews