[AccessD] Standard vs. Class Module: RESEND

Jim DeMarco Jdemarco at hshhp.org
Mon Feb 10 07:32:00 CST 2003


>'m familiar with PublicNotCreatable instancing in VB6
>>In VB6 it's better to use GlobalMultiUse attribute value in ActiveX DLL lib(s) of class modules of utility/generic code.
Thanks.  I was just referring to the instancing type in general, not in the case of your example.

Jim DeMarco 


-----Original Message-----
From: Shamil Salakhetdinov [mailto:shamil at smsconsulting.spb.ru]
Sent: Saturday, February 08, 2003 3:23 PM
To: accessd at databaseadvisors.com
Subject: Re: [AccessD] Standard vs. Class Module: RESEND


<<<
So in the calling db there's a reference to the library and I can just use the property without declaring a variable for it anywhere?  Neat.
>>>
Yes, Jim,
 
But there is an overhead on using Property Get with testing for Is Nothing...
And such calls cannot be used in queries...
 
But IMO all that can be neglected - do you see any more severe side-effects of this technoque?
 
>'m familiar with PublicNotCreatable instancing in VB6
In VB6 it's better to use GlobalMultiUse attribute value in ActiveX DLL lib(s) of class modules of utility/generic code.
 
Strange they (MS) didn't do/let to the same attributes for MS Access custom class modules...
 
Shamil
 

----- Original Message ----- 
From: Jim DeMarco <mailto:Jdemarco at hshhp.org>  
To: accessd at databaseadvisors.com 
Sent: Saturday, February 08, 2003 4:59 PM
Subject: RE: [AccessD] Standard vs. Class Module: RESEND


Thanks Shamil.  I'm familiar with PublicNotCreatable instancing in VB6 but haven't really touched Access Libraries.  Interesting technique.  So in the calling db there's a reference to the library and I can just use the property without declaring a variable for it anywhere?  Neat.
 
BTW, I finally see these messages I was having trouble with a day or more after I sent them.  Go figure.
 
Jim DeMarco

-----Original Message-----
From: Shamil Salakhetdinov [mailto:shamil at smsconsulting.spb.ru]
Sent: Wednesday, February 05, 2003 6:05 PM
To: accessd at databaseadvisors.com
Subject: Re: [AccessD] Standard vs. Class Module: RESEND


<<<
Dim oUtil As cUtil
  Set oUtil = New cUtil
  oUtil.IsLoaded "myform"
>>>
Jim,
 
For utility classes you'd better use what is called singleton classes/object instances:
 
- let's image your custom class is called CMyClass and it has only one method 
 
Public Function Test()
  MsgBox "TEST"
End Function
 
- let's also imagine/assume that this class is located in MS Access library database and that is has its Instancing prioperty set to "2 - PublicNotCreatable"
 
- then you can create a standard helper module with the following code:
 
Private mobjCMyClass As CMyClass
 
Public Property Get CMyClass() As CMyClass
  If mobjCMyClass Is Nothing Then
    Set mobjCMyClass = New CMyClass
  End If
  Set CMyClass = mobjCMyClass
End Property
 
- having all that you can call your custom class' CMyClass Test method by simply using the following code line:
 
CMyClass.Test
 
- and you guaranteed to have only one instance of your custom class during your app lifetime and you've type ahead/intellisense while you typing your code even if your custom class is located in library database and you don't need to type three code lines to call one utility method of your utility/generic function custom class...
 
Just some info on singletons and other custom classes' usage "tricks",
Shamil
 

----- Original Message ----- 
From: Jim  <mailto:Jdemarco at hshhp.org> DeMarco 
To: accessd at databaseadvisors.com 
Sent: Wednesday, February 05, 2003 8:50 PM
Subject: RE: [AccessD] Standard vs. Class Module: RESEND

Sent early AM and so sign of this one.
 
 
No clear cut answer to this question.  I normally put any code that I feel I will reuse in a class module (by reuse I mean within the same app only, or many apps).  A couple of examples:
 
1. I used to have a problem remembering the provider/connect string for Access and SQL OLEDB provides used when opening an ADO connection and/or recordset(s).  I wrapped the code I use to open connections and create recordsets in a class, cDatabase.  Now when I want to use ADO I create an object of type cDatabase, call the OpenConnection method, pass in the mdb or SQL DB, and pass a parameter telling the class what type of db I'm using and I've got my connection.
Ex.
<snip>
Dim oDB As cDatabase
Dim rs As ADODB.Recordset
    Set oDB = New cDatabase
    oDB.OpenConnection "mydb.mdb" 'mdb is default so we don't have to pass optional db type argument
    Set rs = oDB.OpenRecordset ("mytablequeryorsql")
</snip>
I don't have to remember or find the provider/connect string anymore.
 
2. I wrote some code that reads setup/configuration settings from an XML file.  Once it was done I realized I'd like to add this functionality to more apps so I ported it into a class module.  Now with no knowledge of XML my team of developers can add this functionality to their apps by importing the class module.
 
This is not to say a one-off class is not out of the realm of possibility.  As J. Colby mentioned in a earlier post, if you need certain functionality in more than one place in a single app classes make it very easy to add that functionality without copy/paste or reviewing a code module to see "how it works" or how to use it.  
 
We all have stand alone functions that belong in standard modules.  One common module (here at least) is basUtil containing utility functions like IsLoaded to check whether a form or Access object is currently open (things not related to the function of the system).  There's nothing stopping you from putting those in a class.  Why bother?  Class objects implement type ahead code functionality.  Imagine then how easy it would be to access your utility functions by calling an object of type cUtil as follows:
<snip>
Dim oUtil As cUtil
  Set oUtil = New cUtil
  oUtil.IsLoaded "myform"
</snip>
I'd normally have to take a look at basUtil to see what functionality was in there but the class object's type ahead would alleviate that (actually, this was a last minute thought but I think I'll give it a try!).

HTH, 

Jim DeMarco 
Director of Product Development 
HealthSource/Hudson Health Plan 

-----Original Message-----
From: Myke Myers [mailto:mmmtbig at bellsouth.net]
Sent: Monday, February 03, 2003 6:44 PM
To: accessd at databaseadvisors.com
Subject: [AccessD] Standard vs. Class Module


Can anyone describe how to determine when to use a standard module and when to use a class module in Access?
 
TIA    Myke
 



***********************************************************************************
"This electronic message is intended to be for the use only of the named recipient, and may contain information from HealthSource/Hudson Health Plan (HS/HHP) that is confidential or privileged. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution or use of the contents of this message is strictly prohibited. If you have received this message in error or are not the named recipient, please notify us immediately, either by contacting the sender at the electronic mail address noted above or calling HS/HHP at (914) 631-1611. If you are not the intended recipient, please do not forward this email to anyone, and delete and destroy all copies of this message. Thank You".
***********************************************************************************




***********************************************************************************
"This electronic message is intended to be for the use only of the named recipient, and may contain information from HealthSource/Hudson Health Plan (HS/HHP) that is confidential or privileged. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution or use of the contents of this message is strictly prohibited. If you have received this message in error or are not the named recipient, please notify us immediately, either by contacting the sender at the electronic mail address noted above or calling HS/HHP at (914) 631-1611. If you are not the intended recipient, please do not forward this email to anyone, and delete and destroy all copies of this message. Thank You".
***********************************************************************************




***********************************************************************************
"This electronic message is intended to be for the use only of the named recipient, and may contain information from HealthSource/Hudson Health Plan (HS/HHP) that is confidential or privileged.  If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution or use of the contents of this message is strictly prohibited.  If you have received this message in error or are not the named recipient, please notify us immediately, either by contacting the sender at the electronic mail address noted above or calling HS/HHP at (914) 631-1611. If you are not the intended recipient, please do not forward this email to anyone, and delete and destroy all copies of this message.  Thank You".
***********************************************************************************

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://databaseadvisors.com/pipermail/accessd/attachments/20030210/850ae8e1/attachment-0002.html>


More information about the AccessD mailing list