O'Reilly logo

Beginning Access™ 2007 VBA by Denise Gosnell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required