Access project references

G

Guest

This is a two part question regarding Access 2002.

First, I tried setting a reference from one .mdb file to another. The only
thing that was exposed was public code in regular modules, not class modules,
which pretty much negates the value of the reference. Is there something
extra I have to do to expose classes?

Second, I actually plan to do this programmatically. The reason is that
there may be a number of databases with identical "interfaces" but different
data and specific code, and depending on the situation I want to be able to
point to one or the other. So the code will always look the same on the
"master" (referencing) side regardless of which "slave" .mdb is referenced,
the data passing format will be identical, and the details of what goes on in
the slave .mdb will be opaque to the master; it will simply get a result in
the desired fashion.

I can see from the documentation how to change references using VBA, but
there's nothing that says how actually to use that when writing code using
referenced types. In other words, say I can reference either Slave1.mdb or
Slave2.mdb. Assume both have a class MySlaveClass that I want to reference
(assuming I can expose classes per my first question). How do I actually
write code that accesses that class? I can't write "Slave1.MySlaveClass"
because that would only work for Slave1. Do I just write MySlaveClass and
hope it hooks up in real time? I'm assuming there's a fair bit of late
binding here, so I'm trying to minimize the "boundary crossings" between the
master and slave...

It seems like this must be doable (or else there would be no value
whatsoever to being able to programmatically change references), so any
comments on actually how to do it would be appreciated.

Thanks!!
BnB
 
T

Tony Toews [MVP]

BnB said:
I can see from the documentation how to change references using VBA,

I can't answer your questions as I haven't tried doing all that.
However before you get too far down this road double check that this
all work in MDEs. Assuming you will be shipping MDEs. They are much
more restrictive than MDBs when it comes to references.

For example you can't replace a referenced MDE from an MDE even if
none the subroutines, functions and parameters have changed. But
only code inside has changed. Access won't let you do this. I don't
recall the exact error message.

Also see my Add-in Tips, Hints and Gotchas page at
http://www.granite.ab.ca/access/addins.htm if there is anything there
that might be of assistance.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
 
G

Guest

Thanks for the heads-up. Right now this is pretty "researchy", so an MDE is
pretty far away. At that point, DLLs would probably be best. But for now I'm
trying to plod along a bit more simplistically.

BnB

(PS you probably know, but at least some of the links in your article no
longer work... not that you spend all day keeping up with MS article
changes... :) )
 
G

Guest

For anyone that was curious about this, I just figured out part of my answer.
For a class to be exposed in a reference, it has to have the "instancing"
property set to PublicNotCreatable (the only other option besides Private).
This is right below where you set the name. The default is Private (which is
why I couldn't see any classes before).

This means that in the referencing project, you can declare a variable of
that class, but you can't use New to create a new object. If you try, you'll
get a compile error that says "Invalid use of New".

Note that in any such public class, if there are public
methods/properties/etc. that use other classes as parameters or return
values, those classes must also be public. The compile error message is a bit
of a mouthful if you don't, but when you think about it, it makes sense.

BnB
 

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