Code Library

G

Guest

I am experimenting with creating a code library to house my commonly used
code. I use class modules heavily to build custom objects for my
applications.

I created a MDB file and put into it some public functions/subs as well as a
user defined class module.

Then I created a new MDB and explicitly set a reference to the code library.

All of my public subs/functions are accessible via the application.
However, when I attempt to instantiate an object of my user defined class
module, it states that the user defined type is not defined.

Am I doing something wrong? Can somebody help me out?

Thanks in advance.
 
G

Guest

When asking a question concerning code, it is very helpful if you post the
code and point out the line where the error occurs. The error number in
addition to the error message is also helpful.
 
G

Guest

HEre is teh code in the application. I try to instantiate an object of
clsExpSource

Private mObjExpSource As clsexpsource

Private Sub Form_Load()
Set mObjExpSource = New clsexpsource
End Sub

I get the compilation error "User-Defined Type not defined".

Here is a sample of the class module clsExpSource which resides in the Code
Library.
Option Compare Database
Option Explicit

Private Const mConExpSourceTbl = "TBL_REF_EXP_SRC"

Public Event AfterLoad()
Public Event DoesNotExist(intSourceCode As Integer)

Private mIntSourceCode As Integer
Private mStrSourceDesc As String
Private mStrCLPFieldName As String
Private mVarBOBTrend As Variant
Private mBoolHasWorksheet As Boolean
Private mBoolShowDetails As Boolean

Private mRstData As DAO.Recordset

Public Property Get SourceTable() As String
SourceTable = mConExpSourceTbl
End Property

Public Property Get SourceCode() As Integer
SourceCode = mIntSourceCode
End Property

Public Property Let SourceCode(intSourceCode As Integer)
mIntSourceCode = intSourceCode
End Property

Private Sub Class_Initialize()
Set mRstData = CurrentDb.OpenRecordset(mConExpSourceTbl)
End Sub

Private Sub Class_Terminate()
If mRstData Is Nothing Then

Else
mRstData.Close
Set mRstData = Nothing
End If
End Sub

Public Sub Load(intSourceCode As Integer)
mIntSourceCode = intSourceCode

With mRstData
If .EOF And .BOF Then
RaiseEvent DoesNotExist(intSourceCode)
Else
.FindFirst "EXP_SRC_CD = " & mIntSourceCode

If .NoMatch Then
RaiseEvent DoesNotExist(intSourceCode)
Else
Call GetData
End If
End If
End With
End Sub

Private Sub GetData()
With mRstData
mStrSourceDesc = .Fields("EXP_SRC_DESC").Value
mStrCLPFieldName = .Fields("CLP_FIELD_NAME").Value
mVarBOBTrend = .Fields("BOB_TREND").Value
mBoolHasWorksheet = .Fields("HAS_WKS").Value
mBoolShowDetails = .Fields("SHOW_DETAILS").Value
End With

RaiseEvent AfterLoad
End Sub
 
G

Guest

The error message is it can't find your class module. First try copying it
into your application mdb to see that it is working correctly.
Beyond that, I don't know that I can help. I don't recall ever having used
a class module in a code library. Reading what I have available, I don't see
anything that sets a class module apart from a standard module.
 
G

Guest

THank you - yes I had done that part first. It works when the code is in the
application MDB itself. The issues was how to convert it into a library so
that the class may be used from multiple different applications. Thanks for
your help Klatuu.
 
G

Guest

I will save this thread and do a litte experimenting. This is something we
may all want to know. (It may not be until tomorrow, though)
 
R

Rick Brandt

Klatuu said:
I will save this thread and do a litte experimenting. This is
something we may all want to know. (It may not be until tomorrow,
though)

Classes used in a code library referenced file are not exposed because they
are not "public". There is a hack that makes them work, but I don't recall
the specifics. It involves saving the class module as text, making a change
in the resulting text file (something in the header?) and then rebuilding
the module from the text file.

You might find the information if you search these groups as I know it has
been discussed on more than one occassion, but not recently I don't think.
If I find the reference I will post back.
 
R

Rick Brandt

Rick said:
Classes used in a code library referenced file are not exposed
because they are not "public". There is a hack that makes them work,
but I don't recall the specifics. It involves saving the class
module as text, making a change in the resulting text file (something
in the header?) and then rebuilding the module from the text file.

You might find the information if you search these groups as I know
it has been discussed on more than one occassion, but not recently I
don't think. If I find the reference I will post back.

Here is a thread that discusses this. Apparently there are two
work-arounds, neither of which is completely satisfactory in all cases.

http://groups.google.com/group/comp...read/thread/8bffb9af0a10e395/2dc035019af7c291
 
T

Tony Toews [MVP]

Rick said:
I am experimenting with creating a code library to house my commonly used
code.

See my Add-in Tips, Hints and Gotchas page at
http://www.granite.ab.ca/access/addins.htm for some tips.
I use class modules heavily to build custom objects for my
applications.

No idea about class modules though.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
 
R

RHutcheson via AccessMonster.com

Go to Treepad.com and download the free version of their product "Treepad".
I have been using it for years to store code I reuse on a regular basis.
Treepad creates a visual "tree" like a directory that you can add "nodes" to
and in each "node" you can cut or paste your code. It can run from USB (or a
floppy in the older machines) without needing to be installed on the computer
so there is no conflict if you are working on a business machine where they
don't allow you to install any programs without going through the IT dept.
The paid version of their program will allow you to save visuals, webpages,
and whatnot. If you want a nice spell checker that runs in any application
you're using, Googlem "TinySpell" - also a free version.

RHutcheson
 

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