[AccessD] Access 2010 or later - storing and referencing code in libraries

Jim Dettman jimdettman at verizon.net
Thu Jun 17 11:50:38 CDT 2021


John,

 Don't know the answer to this right off, but the docs/comments I find all
say that the VB_Creatable attribute is ignored with VBA.  I know you said
you've done this in the past, but all these docs/comments are more recent
and I wonder if a change might have been made, or if something else that was
done cut the ability to do that off.

 But I did find this, which I think you'll find interesting and may be of
help:

How to use a class (object) from outside of the VBA project in which it is
declared

https://docs.microsoft.com/en-us/previous-versions/office/troubleshoot/offic
e-developer/set-up-vb-project-using-class

  Using a helper function, it shows how to instantiate a class in another
project.

Jim.

-----Original Message-----
From: AccessD On Behalf Of John Colby
Sent: Thursday, June 17, 2021 12:16 PM
To: Access Developers discussion and problem solving
<accessd at databaseadvisors.com>
Subject: [AccessD] Access 2010 or later - storing and referencing code in
libraries

I need assistance creating a library file, using Access 2010, which
contains CREATABLE classes.

If you export a class made in Access 2010 using the 2007 file format, in
the header it will have a set of properties looking like this:

VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "dclsFrm"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Compare Database
Option Explicit

Back in the day, I would change vb_Creatable as follows:

  Attribute VB_Creatable = True

What this does is allows the class to be stored in an MDS file, then
reference the MDA and use the class from there.  The vb_Creatable
propert specifically allows the class to be instantiated using "Dim MyCls
as new clsXYZ"

Without the file having the VB_Creatable = true, the class can be seen
but cannot be instantiated.

So... I export the class, I edit the file in a text editor setting
vb_Creatable = true, I reimport it back into the file.  If I export it back
out, the property has been changed back to VB_Creatable=False.

And of course, if I reference the library, and try to instantiate the class
it fails to compile.

Understand that I have the exact same code in an old MDA file.  If I open
that mda file WITH Access 2010 and export the class to a text file the
vb_Creatable is in fact True.

I am utterly failing to create an MDA file in 2007 file format which allows
me to do this thing.  I am unable to even truly create an MDA file.  I can
call it .MDA but the lock file will be .Accdb.

I can create an Accda file but it too fails to retain the vb_Creatable =
true, and any file stored in said file will not instantiate.

This is really basic stuff.  I used it for a decade to store my framework
and dozens of classes in C2DbFramework, reference the mda file and used "as
new" syntax.  I no longer can do this.I can't find any reference out on
google to doing this.  Lots of stuff about these hidden properties of
classes, most of it wrong, none of it discussing using classes from a
library file.

Help me Obi Wan...  Is there an Obi Wan left amongst us?

--
John W. Colby
Colby Consulting
-- 
AccessD mailing list
AccessD at databaseadvisors.com
https://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com



More information about the AccessD mailing list