"Include" Or "Import" VBA modules (1 Viewer)

swisstoni

Registered User.
Local time
Yesterday, 20:25
Joined
May 8, 2008
Messages
61
Hey guys,

Either I'm missing something really basic or it doesn't exist...

In Java for example, I could call import *** package name ***

I've written a VBA module with some standard library functions I'll want to use, how can I import that into the VBA code for a form?

Google is proving fruitless, partly because I'm not sure what to search for!

Thanks.
 

ecawilkinson

Registered User.
Local time
Today, 04:25
Joined
Jan 25, 2005
Messages
112
in the VBA editor, go to Tools>References, then browse...change the file filter to .mdb and select the db containing the module. It is for this reason that it is always good to change the VBA project name to something meaningful. Obviously the module has to be in database.

HTH,
Chris
 

swisstoni

Registered User.
Local time
Yesterday, 20:25
Joined
May 8, 2008
Messages
61
The module I want is inside the database I'm using...

I did the above and I got:

"Name conflicts with existing module, project or object library"

Is that method meant for referencing modules from other databases?
 

Banana

split with a cherry atop.
Local time
Yesterday, 20:25
Joined
Sep 1, 2005
Messages
6,318
You can't have two modules with same names- you will have to look for where there are same names and change one of them.

This is also true if you have a module and a function or sub with same name.
 

swisstoni

Registered User.
Local time
Yesterday, 20:25
Joined
May 8, 2008
Messages
61
The module already shows up within my project... as per this screenshot:

http://img516.imageshack.us/img516/1913/shotpq5.jpg

I just right clicked my database and went to "insert module" - that's what Functions is in the screen shot.

But how can I use the functions within that module in, for example, the "Form_frmCats" code?
 

DJkarl

Registered User.
Local time
Yesterday, 22:25
Joined
Mar 16, 2007
Messages
1,028
The module already shows up within my project... as per this screenshot:

http://img516.imageshack.us/img516/1913/shotpq5.jpg

I just right clicked my database and went to "insert module" - that's what Functions is in the screen shot.

But how can I use the functions within that module in, for example, the "Form_frmCats" code?

If you declare the functions you create in the Module "Functions" as Public, they can be called from anywhere in the database. VBA is not like Java, in Java everything you create is a class and must be imported or implemented in order to be used. In VBA Modules are really just containers of functions (methods). You can create Class Modules in VBA, but they are not exactly the same as Classes in Java.
 

swisstoni

Registered User.
Local time
Yesterday, 20:25
Joined
May 8, 2008
Messages
61
Ahhh all I was missing was the public keyword!

Many thanks.
 

Users who are viewing this thread

Top Bottom