free tracking

October 9, 2007

MS Access Code in a seperate Database

**Warning** This is technical.

A friend over at omnitec.com asked me tonight how to call a procedure in a remote Access database. Of course at the time I could think of exactly how to do this, it kind of caught me by surprise. I gave some sort of answer that was pretty close but not exactly right. After I got home and was sitting down for a minute it dawned on me how this is done.

This can be accomplished in a few easy steps.

  1. Rename the database with the code you want to run with a .mda extension. Actually I don’t think you even have to do this.
  2. Link to that database under tools and references from the Visual Basic code window and add in a reference to the file above using the browse button.

You can now call any public function in the linked database from your existing database.

A couple things to keep in mind:

  • The tables in the linked database needs to reference things using the ‘codedb’ prefix instead of the ‘currentdb’ prefix. See ‘codedb’ in the access help file.
  • The .mda file will be linked statically so any file path changes will break this connection and cause a hard error that is not easy to recover from. You can search the web for code to automatically establish the link or email me.
  • In order to link to existing tables the links must be established in the .mda file also. A work around is to have a function in your .mda that relinks any tables with a passed pathname.

Spread the word

del.icio.us Digg Furl Reddit Help

Permalink • Print
Made with WordPress and an easy to use WordPress theme • Sky Gold skin by Denis de Bernardy