[AccessD] Building classes for tables

John Colby jwcolby at ColbyConsulting.com
Wed Nov 16 13:10:02 CST 2005


Steve,

This is an example of one of my classes that just stores data values from a
record:

Private mdb As DAO.Database
Private mlngTOID As Long
Private mlngTTID As Long
Private mlngStep As Long
Private mstrQry As String       'The query name of any
Private mstrSQLCode As String   'The SQL or vb code if any
Private mstrDescription As String   'The description of the operation
Private mstrType As String      'Qry, VBA, SQL
Private mblnExecute As Boolean  'This is an execute query
Private mstrQryType As String   'SEL;DEL;UPD;APP
Private Sub Class_Terminate()
    Set mdb = Nothing
    Debug.Print "dclsTransformOperation.Class_Terminate: TOID=" & mlngTOID
End Sub

Function mInit(rst As DAO.Recordset)
On Error GoTo Err_mInit
    With rst
        mlngTOID = !TO_ID
        mlngTTID = !TO_IDTT
        mlngStep = !TO_Step
        mstrQry = StrNull(!TO_Query)
        mstrSQLCode = StrNull(!TO_SQLCode)
        mstrDescription = StrNull(!TO_Description)
        mstrType = StrNull(!TO_Type)
        mblnExecute = !TO_Execute
        mstrQryType = StrNull(!TO_QryType)
    End With
Exit_mInit:
Exit Function
Err_mInit:
        MsgBox Err.Description, , "Error in Function
dclsTransformOperation.mInit"
        Resume Exit_mInit
    Resume 0    '.FOR TROUBLESHOOTING
End Function
Function StrNull(varVal As Variant) As String
    If IsNull(varVal) Then
        StrNull = ""
    Else
        StrNull = varVal
    End If
End Function
Property Get pTOID() As Long
    pTOID = mlngTOID
End Property
Property Get pTTID() As Long
    pTTID = mlngTTID
End Property
Property Get pStep() As Long
    pStep = mlngStep
End Property
Property Get pQry() As String
    pQry = mstrQry
End Property
Property Get pSQLCode() As String
    pSQLCode = mstrSQLCode
End Property
Property Get pDescription() As String
    pDescription = mstrDescription
End Property
Property Get pType() As String
    pType = mstrType
End Property
Property Get pExecute() As Boolean
    pExecute = mblnExecute
End Property
Property Get pQryType() As String
    pQryType = mstrQryType
End Property

Notice that:

All dim statements are private
All dim statements have a type
All property get statements have a type
Variables and property statements do not follow my table naming standards.
But they can.
I use a p as the prefix for all properties so they group in the object
browser.  Just my own standard.

There are no Property let but there needs to be an option to build them

Of course the wizard will not build the Init()  functions or surrounding
code.
The alternative of passing in a recordset is to pass in variables directly.
I kind of like passing in a recordset because the class can do its own
testing for the null values.  If you don't do that then the init function
has to have variants to prevent run time errors when the record contains
nulls.

Anyeay, just the basics is what I am looking for.

John W. Colby
www.ColbyConsulting.com 

Contribute your unused CPU cycles to a good cause:
http://folding.stanford.edu/

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Steve Conklin
Sent: Wednesday, November 16, 2005 1:37 PM
To: 'Access Developers discussion and problem solving'
Subject: Re: [AccessD] Building classes for tables


LOL - ok, now I get it, but I haven't done it; but I'll collaborate here if
interested ... After lunch today, I'm at this PC until 10:00 pm ET.  

Steve



-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of John Colby
Sent: Wednesday, November 16, 2005 1:22 PM
To: 'Access Developers discussion and problem solving'
Subject: Re: [AccessD] Building classes for tables

yes

John W. Colby
www.ColbyConsulting.com 

Contribute your unused CPU cycles to a good cause:
http://folding.stanford.edu/

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Steve Conklin
Sent: Wednesday, November 16, 2005 1:05 PM
To: 'Access Developers discussion and problem solving'
Subject: Re: [AccessD] Building classes for tables


John:
I'm unclear about this thread ,,, are you looking for something like

For each fld is rs.fields
	stDeclares = "dim " &  getTypePrefix & fld.name
	stGet ="Property Get " & fld.name & vbcrlf & _ 
	fld.name & "=" &  getTypePrefix & fld.name & vbcrlf & _ 
	"End Property"
Next 'fld

Write this all out to disk and then do a Modules.addfromfile ?

Steve




More information about the AccessD mailing list