Exposed Library Db Class and New Keyword

E

Ed Kopta

I have a class in a library db that I've exposed as per
http://www.mvps.org/access/modules/mdl0034.htm

I am having trouble using it in another db though. the statement

Set cls = New MyClass

will not compile (inappropriate use of New Keyword). Is there a way to make
this work (by messing with other values in the header in addition to
Attribute VB_Exposed, say)? Failing that, should I write a function to
return an instance of the class instead of using New?

Thanks for any help you can give me,

-Ed Kopta
 
D

Dirk Goldgar

Ed Kopta said:
I have a class in a library db that I've exposed as per
http://www.mvps.org/access/modules/mdl0034.htm

I am having trouble using it in another db though. the statement

Set cls = New MyClass

will not compile (inappropriate use of New Keyword). Is there a way
to make this work (by messing with other values in the header in
addition to Attribute VB_Exposed, say)? Failing that, should I write
a function to return an instance of the class instead of using New?

I haven't had occasion to do this myself, but I believe you have to
create a public "class factory" function in the library DB; e.g.,

Public Function NewMyClass() As MyClass

Set NewMyClass = New MyClass

End Function

(or maybe, "As Object")

Then you would call this function from your current database:

Set cls = LibDB.NewMyClass()

As I said, I haven't done this, but I think the necessary approach is
something like that.
 
P

Paul Overway

The article you reference in the link works perfectly...I've used it for
several years/versions now. You DO have to follow the instructions exactly
though.

Dirk's suggestion would work too, if you only need a single instance.
Otherwise, you'd need to create a function to manage the various instances.
 
D

Dirk Goldgar

Paul Overway said:
The article you reference in the link works perfectly...I've used it
for several years/versions now. You DO have to follow the
instructions exactly though.

Shame on me, I should have followed the link and tried it out. I didn't
know you could do that.
 
E

Ed Kopta

Well, I thought I followed the instructions exactly. But looking back I see
that the article uses .mda files for the library db while mine is a .mde
file. Is that a crucial difference?

And just to be clear, I should use the Import/Export commands in the main
Access window and not those in the VB Editor? Or is that a holdover from
previous versions?

The class is exposed, so that much has worked. The Dim statement compiles
fine (but not with "New" included). I'm just having difficulty creating a
new instance of it.

-Ed Kopta
 
E

Ed Kopta

OK, upon further messing around I have it working. In addition to changing
Attribute VB_Exposed to True, I also did the same with Attribute
VB_Creatable.

What do all those Attributes do, I wonder?

Thanks for the help everyone!

-Ed Kopta
 
P

Paul Overway

The actual file extension for the library file doesn't matter (MDA/MDE/MDB),
but it should be compiled to an MDE "type" database. IMPORTANT: If you
recompile the library, you must also recompile any files that have a
reference to it.

You are correct that some of the article points to the older menus in Access
97. However, the basics are the same...export the class you want to make
public to a text file, modify the attributes, create a new class, import the
text back into a new class.

This is the header section from a class I use for a MDE library in the
manner described in the article.

VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "clsLinkManager"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = True

The VB_Creatable atrribute is visible while you are in the VBA editor...look
at the class properties and you'll see Instancing, which should be
Private....if you set Instancing to PublicNotCreatable, the VB_Creatable
attribute in the text file will be False.

The header attributes are all constructs of VB class files...with a few
omissions. The following is an example of the header section for a class
developed in VB:

VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "Crypto"
Attribute VB_GlobalNameSpace = True
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True

Notice that VB_Exposed is always set to true in a VB class....no tinkering
with text files is necessary. So, Microsoft deliberately crippled this
functionality for MDE files, although I'm not sure why. In any case, I'm
glad someone figured it out.
 

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