By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,469 Members | 2,402 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,469 IT Pros & Developers. It's quick & easy.

expose class modules of a referenced mde

P: n/a
Greetings all,

I've been reading for the last couple hours posts on this site and
various MS sites about reference libraries and class modules.

System: Windows 2K running an A2K db with various standard modules and
a handful of custom class modules. Stripped out the standard and class
modules and put them in a stand-alone mdb which was then converted to
an mde and referenced from another mdb (later, it will be an mde, but
i'm only in development now, so it's still an mdb).

Problem: The global variables, public functions and subroutines of the
standard modules are there as they should be, but the class modules are
not. I've tried exposing them using both of Terry Kreft's suggestions
for such things.

Method 1: Referencing the class with a public function in one of the
standard modules in the referenced db. Call like:

Public Function fMyClass() as cMyClass
Dim mc as cMyClass
Set mc = New cMyClass
Set fMyClass = mc
End Function

Method 2: Called the "unsafe way" by Kreft, but supposedly in use by
Lyle Fairfield, et al.:

1. Save class as .txt or .cls file.
2. Change "Attribute VB_Exposed" to True.
3. Insert|File... into new class module with the same name.

That should result in an externally creatable Class Module and allow
calls like:

Dim MyObj as cMyClass
Set MyObj = new cMyClass

With MyObj
'.... do stuff
End With

Using method number 1 gets me nowhere.
Method 2 results in an "Invalid use of New keyword error" when the code
compiles in the referencing database. Removing the New keyword results
in "Variable not defined".

All of the class modules wrap actual objects and assign (set)
properties for them by referencing actual objects on the forms.

Am I misreading these instructions, or are they not valid for A2K? How
do I expose a class module in a referenced mde for use in the
referencing mdb?

Apr 14 '06 #1
Share this Question
Share on Google+
14 Replies


P: n/a
> Method 2: Called the "unsafe way" by Kreft, but supposedly in use by
Lyle Fairfield, et al.:

1. Save class as .txt or .cls file.
2. Change "Attribute VB_Exposed" to True.
3. Insert|File... into new class module with the same name.
That should result in an externally creatable Class Module and allow
calls like:

Dim MyObj as cMyClass
Set MyObj = new cMyClass
With MyObj
'.... do stuff
End With Method 2 results in an "Invalid use of New keyword error" when the
code
compiles in the referencing database. Removing the New keyword results
in "Variable not defined".
All of the class modules wrap actual objects and assign (set)
properties for them by referencing actual objects on the forms.

Am I misreading these instructions, or are they not valid for A2K? How
do I expose a class module in a referenced mde for use in the
referencing mdb?


I too am using the so said "unsafe" mode you described, but I changed also
another line in the header of the exported clase modules:

Attribute VB_Creatable = True

Tyr if this could be your case.

--
PBsoft di Gabriele Bertolucci
www.pbsoft.it
skype: pbsoftsolution
Apr 15 '06 #2

P: n/a
Thanks, I'll give that a shot. Changing the line mentioned in my post
exposes the Class object in the object browser, but doesn't give me any
ability other than declaring varibles of type X. I still can't Set
properties as I can in a db where the classes are local or use the New
keyword. I'll try your suggestion and post back the results.

Thx....Jamey

Apr 15 '06 #3

P: n/a
The header section of your MyClass.cls file should look like this:-

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

Note the VB_Exposed = True and the VB_Creatable = True lines.

BTW; I think I referred to this method as "unsafe" once and that's dogged me
for years, what I meant was that it was undocumented and undocumented
features cannot be relied upon.

--

Terry Kreft
"Jamey Shuemaker" <ca*********@yahoo.com> wrote in message
news:11**********************@i40g2000cwc.googlegr oups.com...
Greetings all,

I've been reading for the last couple hours posts on this site and
various MS sites about reference libraries and class modules.

System: Windows 2K running an A2K db with various standard modules and
a handful of custom class modules. Stripped out the standard and class
modules and put them in a stand-alone mdb which was then converted to
an mde and referenced from another mdb (later, it will be an mde, but
i'm only in development now, so it's still an mdb).

Problem: The global variables, public functions and subroutines of the
standard modules are there as they should be, but the class modules are
not. I've tried exposing them using both of Terry Kreft's suggestions
for such things.

Method 1: Referencing the class with a public function in one of the
standard modules in the referenced db. Call like:

Public Function fMyClass() as cMyClass
Dim mc as cMyClass
Set mc = New cMyClass
Set fMyClass = mc
End Function

Method 2: Called the "unsafe way" by Kreft, but supposedly in use by
Lyle Fairfield, et al.:

1. Save class as .txt or .cls file.
2. Change "Attribute VB_Exposed" to True.
3. Insert|File... into new class module with the same name.

That should result in an externally creatable Class Module and allow
calls like:

Dim MyObj as cMyClass
Set MyObj = new cMyClass

With MyObj
'.... do stuff
End With

Using method number 1 gets me nowhere.
Method 2 results in an "Invalid use of New keyword error" when the code
compiles in the referencing database. Removing the New keyword results
in "Variable not defined".

All of the class modules wrap actual objects and assign (set)
properties for them by referencing actual objects on the forms.

Am I misreading these instructions, or are they not valid for A2K? How
do I expose a class module in a referenced mde for use in the
referencing mdb?

Apr 15 '06 #4

P: n/a
TTBOMR the requirements for this changed from AC97 to AC2K. I have
never found enough value in using an exposed class in a referenced mdb
or mde to justify my continuing on with it.
I did try to write code that would expose Classes, Forms and Reports
but I was not successful in AC Version >=2K.
Actually I have not recently found much value in VBA Classes at all,
except in the rare case when one needs to have multiple instances of
some code running at the same time, or where a process uses a great
number of variables over and over again; these variables can be
initalized once in the Class_Initialize procedure. A Soundex procedure
is an example.
But in general Classes have no advantage over Standard Modules at all,
except to make their creator feel accomplished. They used to be slower
(who has checked lately?) and remain clumsier and no more powerful than
Standard Modules.

Apr 15 '06 #5

P: n/a
Actually, I prefer them a great deal to standard modules because they
serve as wrappers for other objects which basically allows for
multi-tiers of events all responding to the same thing via the
WithEvents keyword or a RaiseEvent statement. Also allows me to build
in design tools for users trying to create their own forms or reports
and have a consistent set of controls on them that do exactly the same
thing my controls do as well as looking and feeling the same.

You can accomplish all that without using classes, sure...but who'd
want to? I would estimate about 15-20% more design time for a new
classs module up-front, but worlds less design time down the road.

As for tying them in with a reference to another mde...well, that's the
part I'm still exploring, and step A is finding a way to do it, which
thus far hasn't worked.

I'll try your suggestions, Terry. Missed the VB_Creatable setting.
Should've seen that myself on closer review.

Apr 15 '06 #6

P: n/a
Alright, I ran this thing again and replaced both of the class
attributes mentioned above. Still getting the same errors (Invalid use
of New keyword/Variable not defined) in the set statements for the form
class module that assigns this custom class to an object in the UI.

I exported the class again, and it seems that it is retaining the
"Exposed" attribute setting, but the "Creatable" attribute has been set
back to False.

I'll tinker a little more and let you know what I find out.

Apr 16 '06 #7

P: n/a
When importing it you are
creating a new class module
using the Insert/File menu option

rather than using File/Import File, aren't you?

--

Terry Kreft
"Jamey Shuemaker" <ca*********@yahoo.com> wrote in message
news:11*********************@i39g2000cwa.googlegro ups.com...
Actually, I prefer them a great deal to standard modules because they
serve as wrappers for other objects which basically allows for
multi-tiers of events all responding to the same thing via the
WithEvents keyword or a RaiseEvent statement. Also allows me to build
in design tools for users trying to create their own forms or reports
and have a consistent set of controls on them that do exactly the same
thing my controls do as well as looking and feeling the same.

You can accomplish all that without using classes, sure...but who'd
want to? I would estimate about 15-20% more design time for a new
classs module up-front, but worlds less design time down the road.

As for tying them in with a reference to another mde...well, that's the
part I'm still exploring, and step A is finding a way to do it, which
thus far hasn't worked.

I'll try your suggestions, Terry. Missed the VB_Creatable setting.
Should've seen that myself on closer review.

Apr 18 '06 #8

P: n/a
Yes, tried both methods in fact. Here's the latest.

Exported the class to a .cls file and altered the settings as above.

Imported it using the import option. That doesn't work because it
doesn't retain the Creatable attribute.
Inserted it from the .cls file. That doesn't work because it doesn't
retain the Creatable attribute.

Changed the .cls file to a .txt file, changed the attributes as above.

Inserted it from the .txt file. That works and properly exposes the
class to a referencing database IF I leave the thing an .mdb.

Access won't let me save it as an .mde for reasons unknown to me. Since
I can't reference an .mdb from an .mde (which is what the final app
will wind up being) it's not very useful to me in its current form. Not
sure what it is about making it an .mde that Access doesn't like, but
for now I'll just leave the standard modules in the reference file and
import the class objects as needed into the app.

If you have any ideas on the .mde deal, let me know.

Thanks for the help up to this point....Jamey

Apr 19 '06 #9

P: n/a
I'll have a look on Friday when I'm back in the office as I don't have A2000
on this laptop.

It certainly works with A2003 (as does importing .cls files).

--

Terry Kreft
"Jamey Shuemaker" <ca*********@yahoo.com> wrote in message
news:11*********************@v46g2000cwv.googlegro ups.com...
Yes, tried both methods in fact. Here's the latest.
<SNIP>
Access won't let me save it as an .mde for reasons unknown to me. Since
I can't reference an .mdb from an .mde (which is what the final app
will wind up being) it's not very useful to me in its current form. Not
sure what it is about making it an .mde that Access doesn't like, but
for now I'll just leave the standard modules in the reference file and
import the class objects as needed into the app.

If you have any ideas on the .mde deal, let me know.

Thanks for the help up to this point....Jamey

Apr 19 '06 #10

P: n/a
> Inserted it from the .txt file. That works and properly exposes the
class to a referencing database IF I leave the thing an .mdb.
Ok. That's correct.
Access won't let me save it as an .mde for reasons unknown to me.
Since I can't reference an .mdb from an .mde (which is what the final
app will wind up being) it's not very useful to me in its current
form. Not sure what it is about making it an .mde that Access doesn't
like, but for now I'll just leave the standard modules in the
reference file and import the class objects as needed into the app.
It's normal that you cannot reference an MDB from an MDE, but Access should
let you create an MDE from an MDB.
What errors are you getting?
Did you try to compile your database? Do you get any errors while compiling?
If you have any ideas on the .mde deal, let me know.


I don't use Access 2000, but can confirm there is no problem using Access
2002.

--
PBsoft di Gabriele Bertolucci
www.pbsoft.it
skype: pbsoftsolution
Apr 19 '06 #11

P: n/a
Hey Gabriele,

To answer your questions:

Yes, I compiled it first. Always do on things like this. Compiles
without error. Even compacted and repaired and that worked fine as
well.

When A2k tries to make the .mde, it gets started (the
compiling/compacting phase, I think) but then runs into some sort of
error with no error code, just the description that it can't create the
..mde...."Unable to create mde" or something like that.

Tried it at home on A2k2 a couple different ways. First, I took an .mdb
in A2k format and copied the .cls file as above, making noted changes,
and saved it as a .cls and a .txt file.

Then I went back into A2k2 to the A2k database and both imported and
inserted the file, as above. Again, the only method that retains both
settings is Inserting the .txt file. Importing the class file doesn't
retain the Creatable attribute, while Inserting the class file retains
neither the Creatable, nor the Exposed attribute.

Once the class module was created (with text file inserted) and saved,
I clicked on the Tools|Database Utilities and the "Make MDE File" menu
option is disabled. I suppose this is because I can't make one.

That out of the way, I converted the database to A2k2 format, and it
worked like a charm. That of course, after having Inserted the .txt
file in the previous A2k version. I tinkered around a bit more and
found that I could Insert either a .cls or a .txt file and have both
attributes retained, but the Import feature would, again, not retain
the Creatable attribute.

For whatever that's worth...Jamey

Apr 21 '06 #12

P: n/a
Jamey,
As promised I had a look at this in the office and it definitely works in
A2k (using the .cls save as well) so why you are having trouble with it I
don't know.
--

Terry Kreft
"Jamey Shuemaker" <ca*********@yahoo.com> wrote in message
news:11*********************@t31g2000cwb.googlegro ups.com...
Hey Gabriele,

To answer your questions:

Yes, I compiled it first. Always do on things like this. Compiles
without error. Even compacted and repaired and that worked fine as
well.

When A2k tries to make the .mde, it gets started (the
compiling/compacting phase, I think) but then runs into some sort of
error with no error code, just the description that it can't create the
.mde...."Unable to create mde" or something like that.

Tried it at home on A2k2 a couple different ways. First, I took an .mdb
in A2k format and copied the .cls file as above, making noted changes,
and saved it as a .cls and a .txt file.

Then I went back into A2k2 to the A2k database and both imported and
inserted the file, as above. Again, the only method that retains both
settings is Inserting the .txt file. Importing the class file doesn't
retain the Creatable attribute, while Inserting the class file retains
neither the Creatable, nor the Exposed attribute.

Once the class module was created (with text file inserted) and saved,
I clicked on the Tools|Database Utilities and the "Make MDE File" menu
option is disabled. I suppose this is because I can't make one.

That out of the way, I converted the database to A2k2 format, and it
worked like a charm. That of course, after having Inserted the .txt
file in the previous A2k version. I tinkered around a bit more and
found that I could Insert either a .cls or a .txt file and have both
attributes retained, but the Import feature would, again, not retain
the Creatable attribute.

For whatever that's worth...Jamey

Apr 21 '06 #13

P: n/a
> That out of the way, I converted the database to A2k2 format, and it
worked like a charm.
Good. Indeed I use AXP and had no problem in creating MDEs.

The reason for you not to be able to create an MDE from AXP is the MDB format.
As you said, you got no problem after converting the file into AXP format.
That of course, after having Inserted the .txt
file in the previous A2k version. I tinkered around a bit more and
found that I could Insert either a .cls or a .txt file and have both
attributes retained, but the Import feature would, again, not retain
the Creatable attribute.


That's the correct way. I knew it.

You can EXPORT class modules with no problem, but CANNOT IMPORT them if you
would like to retain also those two famous attributes.

I don't know the reasons that took Microsoft to choose this "feature", but
hope in Access 2007 it would be possible to use those two attributes without
tricks.

--
PBsoft di Gabriele Bertolucci
www.pbsoft.it
skype: pbsoftsolution
Apr 21 '06 #14

P: n/a
Thanks all for the comments. I think, in the end, I've got a workable
solution anyway. I don't understand the differences that we're seeing
from version to version, but I've got a working reference to the .mde
for the standard modules anyway, and since the classes aren't supported
and to avoid more version type errors, I think I'll stay away from them
anyway. Like I said, I can just import whatever classes I need since I
don't use every class in every project anyway.

Thanks for the help.

Jamey

Apr 21 '06 #15

This discussion thread is closed

Replies have been disabled for this discussion.