views:

146

answers:

3

i’m wondering if it’s possible to load code from an external file to be used in ms access. this is important to allow easy development using version control—.mdb files are impossible to version control.

+1  A: 

You could write a small import/export tool (in the app itself, or in a separate MDB) which uses the Application.SaveAsText and Application.LoadFromText methods. These are undocumented, but once you've typed the method name into the editor it will prompt you with the argument types, which are: ObjectType As AcObjectType, ObjectName As String, FileName As String.

Todd Owen
this is a first step, but isn't there a way to execute external vba code?
knittl
I very much doubt that there is, sorry.
Todd Owen
ok, i'll then go with the solution you commented
knittl
A: 

You might want to consider library database, i.e., and external MDB or MDE that has code that can be used in any MDB/MDE. If you're using an MDE for the front end, then it will have to be recompiled each time the library changes, which can be a real pain if you're trying to use a shared library MDE. This can be done with references, or by Application.Run, the same way you can call functions in the Access wizard database, e.g., the Zoom box:

  Application.Run("UTILITY.BuilderZoom", "MyForm", "MyControl", "Values")

This is how you can launch the "zoom box" that you get in the Access UI when you hit Shift-F2 while in a textbox.

What it's doing is running the BuilderZoom function in the UTILITY database. There is no path specified because it's in the Access folder. If you have your library elsewhere, you'd have to supply the path to Application.Run.

David-W-Fenton
this doesn't solve the problem of not being able to diff/merge/version code in a sane way …
knittl
No, but it means you can centralize your code for re-use in a way that makes it easier to manage.
David-W-Fenton
+2  A: 

See http://stackoverflow.com/questions/187506/how-do-you-use-version-control-with-access-development for an excellent solution. I modified the vb scripts slightly to allow exporting and importing of queries, as well as the other types.

I use these scripts along with Mercurial to do my version control. Using Access 2002 this has been very reliable for me. I restored a previous changeset and rebuilt the MDB and it seemed to work with no problems. Also, remarkably few resources required. One of my projects has 12 changesets committed that take up a total of 16 MB in the repository, and the base mdb is about 10 MB itself. I highly recommend this approach.

mwolfe02
To clarify, this is essentially Todd's suggestion with a link added to an already existing 'small import/export tool'
mwolfe02