Sharing classes via referenced .mdb

Oy Vey

98 lb. Gorilla
Local time
Today, 01:24
Joined
Jun 4, 2004
Messages
18
Hi all...

I've a frustrating situation at the moment. I inherited an architecture that consisted of various access-based applications that used common functionality from modules located in another database. This common database was linked as a reference in the VBE. This is using AccXP.

What I attempted to do this week was to further encapsulate this functionality into a class that would group the most common functions but share data and methods that are otherwise repeated in different modules. That's irrelevant to the issue I've encountered, but that's what I was trying to do.

What I discovered, after finishing and testing the class within the database that housed it, was that an access database that references the other cannot directly reference the object, and on debug or compile, I get a UDT not found error.

What I need to discover is whether it is possible to expose a class to another database that has the first one referenced.

Example:
Code:
SourceDB.mdb
Class Module TestClass

Public Sub Testing
   Msgbox "hi!"
End Sub


TargetDB.mdb
Module Testing
Reference set to SourceDB.mdb

Public Sub UseClass
   Dim t as New TestClass

   t.Testing

End Sub

Oddly enough, the custom class will be available from the Intellisense picklist for a short while. The option will disappear, however, as soon as you try to run or debug it.

Blah.

In any case, if anyone finds a workaround or something that states categorically that this cannot be done, I would appreciate a reply.
 
Ok. After a long weekend and several cups of coffee I think I have a workaround.

To restate the problem simply, an Access project that references a second project cannot use uninstantiated classes from the second project. You can't initialize the class from the first project because it cannot reference that object at all.

The solution is to create, in the second project, a global variable assigned the type of the class you want to use. Next, create a sub that simply instantiates the class. Save off the work and jump to the first project.

Call the sub by referencing the project name and routine name (project2.initializeclass). After running the sub, you have access to the methods and properties of the custom class from the second project in the first project.
 

Users who are viewing this thread

Back
Top Bottom