Startup module for common code

Harry Shmedlap

Registered User.
Local time
Today, 20:53
Joined
Aug 9, 2005
Messages
51
Is there a way, similar to Excel's "personal.xls", to put all my reuseable Access code into one central module?
Thanks in advance.
 
Do you mean to call the functions from different db's? You could create a dll file.
 
I mean also functions and also subroutines.
How do I create a dll from Access?
 
Simple Software Solutions

Hi,
Contrary to popular beleif you can connect to modules from other Mdb's.

Step 1

Create a blank Access mdb that will contain your popular functions and subroutines.

Step 2

Create a module and insert them in there and save your module

Step 3

Open up your main MDB and design an existing module. Go to Tools then Refererences and click on browse. Change the extension to *.mdb in the Look for box.

Navigate to the source code MDB and click ok.

Tick the box in the reference list. It may change the MDB name to db1.

Step 4

Create a blank form and add a text box and a button

Name the Text field TxtFullName

on the OnClick property of the button

Enter the following:

Msgbox db1.ExtractSurname(Me.TxtFullName)

Where db1 is the name of the reference and FunctionName is the name of the function you want to employ.

In the following example I have a function named ExtractSurname() that takes the last word in a persons full name and returns the last complete word.

Example:

LastName = ExtractSurname("Fred Blogs")
LastName = "Blogs"

Type in Fred Blogs into your text field then click the command button

You should now get a message box with the word Blogs appearing

Try this and if it works for, good.
 
DCrake - great stuff. It works well.
At first I had trouble because of conflicts with the project name. I always used the default. Now I changed it to something unique.
But now I'm confused. There is the database name (e.g. GlobalModule.MDB), the Project Name (which I also called GlobalModule) and the module name (which I had to name differently as GlobalModuleSubroutines, or else I got a conflict error).
In the above module I put a subroutine called GlobalModuleTest.
Inside my own database I called the subroutine with:
GlobalModule.GlobalModuleTest
and it works fine.
My question is: how does VBA "know" whether I mean the Project Name or the database file name?
Thanks!
 
Simple Software Solutions

Hi,

glad it works for you. The answer to your question lies in the mapping of your Global Routines MDB. When you go into references and browse to the source file if you select a mdb it knows to look in there, conversely if you are connecting to and adp it can tell the difference.

One thing to note is that do not include anything else in the source mdb or you may get conficts, if you have the source mdb open and then another mdb attempts to reference it at the same time you may get access denied errors.

:)
 
@DCrake
Interesting use of resources. However it seems that you can't create an MDE anymore?
 

Users who are viewing this thread

Back
Top Bottom