14.5. Building the Standard Modules

Now that you have created the properties and methods for the Customer objects, you are ready to begin writing the code in the standard modules.

Try It Out: Building the modBusinessLogic and modDatabaseLogic Modules

The modBusinessLogic module will contain business logic but will not contain any database access calls. The modDatabaseLogic module will contain calls that are specific to the database. Let's create these modules.

  1. Insert a new standard module called modBusinessLogic. Add the following code to the General Declarations of the module:

    Option Compare Database
    Option Explicit
    Const BUS_LOGIC = "modBusinessLogic"
    Public intCustomerLookupId As Integer
  2. Add the following FixNull function to the modBusinessLogic module:

    Function FixNull(varIn As Variant) As String
    
    'this procedure sets null values in the recordset
    'to a null string so an error does not occur when
    'trying to assign the value to a control for display
    
        'if the value is null
        If IsNull(varIn) Then
            FixNull = ""
        Else
            'return the value passed in
            FixNull = varIn
        End If
    
    End Function
  3. Add the following PopulateListFromRecordset procedure to the modBusinessLogic module:

    Sub PopulateListFromRecordset(lstList As ListBox, rsRecordset As _ ADODB.Recordset, intNumCols As Integer) On Error GoTo HandleError Dim intCounter As Integer Dim strItem As String With lstList .RowSource = "" .ColumnCount = intNumCols .RowSourceType = "Value List" End With 'add all of the values in the recordset to the list ...

Get Beginning Access™ 2007 VBA now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.