Using a function in a different mdb

J

JimP

What statements are needed to use a function in a different db, assuming the
reference needs to be set via code? e.g. the code below results in the error
"variable not defined" when calling "MyFunction"- something must be missing.

Dim ref as Reference
Set ref = References.AddFromFile("C:\FunctionMdb")
Call FunctionMdb.MyFunction(Parameter1)
 
S

Stuart McCall

JimP said:
What statements are needed to use a function in a different db, assuming
the reference needs to be set via code? e.g. the code below results in the
error "variable not defined" when calling "MyFunction"- something must be
missing.

Dim ref as Reference
Set ref = References.AddFromFile("C:\FunctionMdb")
Call FunctionMdb.MyFunction(Parameter1)

I don't see Parameter1 declared anywhere. That would definitely cause the
not defined error.

Also, maybe the filename needs to be "C:\FunctionMdb.mdb" ?
 
T

Tony Toews [MVP]

JimP said:
What statements are needed to use a function in a different db, assuming the
reference needs to be set via code? e.g. the code below results in the error
"variable not defined" when calling "MyFunction"- something must be missing.

Dim ref as Reference
Set ref = References.AddFromFile("C:\FunctionMdb")
Call FunctionMdb.MyFunction(Parameter1)

Also note that you can't create a reference in an MDE although you can
in an MDB.

Tony
--
Tony Toews, Microsoft Access MVP
Tony's Main MS Access pages - http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
For a free, convenient utility to keep your users FEs and other files
updated see http://www.autofeupdater.com/
Granite Fleet Manager http://www.granitefleet.com/
 
V

vanderghast

The same thing would happen with the lines:

Dim i As long
i = ADODB.adAffectCurrent


It will compile if you have a reference to ADO, but would claim that you
have an undeclared variable, ADODB, if you remove the reference (and have an
Option Explicit), since it will expect this is a case of an
object-dot-property syntax. As in your case, at compile time, the compiler
does not HAVE the reference to the library you are adding, at runtime, so,
it is assumed a case of objet-dot-property (or method) syntax.

I have never been confronted to a problem requiring the kind of gymnastic
you seem to use, but maybe CallByName would be somehow safer (I mean by
that, still compilable without error, while also keeping Option Explicit)?

Note that under COM, you don't need to really have the final executable
library to produce a compiled version of your application: as long as you
have 'a' definition of the interfaces exposed by the library, at compile
time, that is often enough, and if you have another version of the library,
at run time, that should not create a problem since COM interfaces are
immuable contract... in theory (DLL -Hell). But in any case, I personnaly
would take it safer than removing Option Explicit.



Vanderghast, Access MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top