473,472 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

expose class modules of a referenced mde

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
14 5398
> 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
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
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
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
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
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
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
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
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
> 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
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
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
> 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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Ross A. Finlayson | last post by:
Hi, I'm scratching together an Access database. The development box is Office 95, the deployment box Office 2003. So anyways I am griping about forms and global variables. Say for example...
8
by: MLH | last post by:
Have a look at the procedure below. In particular, note lines 1 and 21... Private Sub JudHrngReqBtn_Click() On Error GoTo Err_JudHrngReqBtn_Click Dim ThisForm As String ThisForm = Me.Name ...
8
by: Paminu | last post by:
I am trying to split my program in different parts. I have a file called mainfile.c that contains the main() function, some global variables and a few other functions. I then have a file...
2
by: jheising | last post by:
All, I'm wondering if anyone can help with a small little issue I'm having. Here's the hypothetical situation: I have an Assembly called FooBaseAssembly with a classed called FooBase. I...
2
by: isamusetu | last post by:
Hello, I have a question. I have a big project, and all the modules are over 100, some of dll was referenced by most of the modules (dll, exe) When one EXE call a DLL, if some functions in the DLL...
3
by: Miguel Ferreira via .NET 247 | last post by:
Hi ! I have developed a class Library with several classes and methods. Its working fine with a windows forms test application, but now i need to create a webservice that will expose those...
13
by: André | last post by:
Hi, i'm developping asp.net applications and therefore i use VB.net. I have some questions about best practises. According what i read about class and module and if i understand it right, a...
4
by: Tom Jones | last post by:
I have an application that was originally built using Visual Studio 2003 that I upgraded to Visual Studio 2005. When I attempt to build the *.msi file in the deployment project, I am getting a...
16
by: ssecorp | last post by:
Is there a way to view all the modules I have available for import from within Python? Like writing in the interpreter: import.modules Also, is there anything like Cpan for Python?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.