Access JumpStart 2.0 | Blog

A Rapid Development Framework for Microsoft Access

Now I have some code.

Here’s what my form looks like so far:

That contains the following module:

'Form_frmAccounts
Option Compare Database
Option Explicit

Private InternalAccount As AccountInterface

Private Function Acct() As AccountInterface
    If InternalAccount Is Nothing Then Set InternalAccount = New AccountCreditCard
    Set Acct = InternalAccount
End Function

Private Sub Form_Current()
    If Not IsNull(CurrentBalance) And Not IsNull(Me.MinimumPayment) And Not IsNull(Me.InterestRate) Then
        Me.txtMonthsToPayOff = Acct.MonthsToPayoff(Me.CurrentBalance, Me.MinimumPayment, Me.InterestRate)
    End If
End Sub

And that is currently using both the interface and an object based on the interface. Class AccountInterface and Class AccountCreditCard. Here are each of those classes:

'Class AccountInterface
Option Compare Database
Option Explicit

Public Function MonthsToPayoff(CurrentBalance As Currency, MinimumPayment As Currency, InterestRate As Single) As Long: End Function
'Class AccountCreditCard
Option Compare Database
Option Explicit

Implements AccountInterface

Private Function AccountInterface_MonthsToPayoff(CurrentBalance As Currency, MinimumPayment As Currency, InterestRate As Single) As Long
    Dim retVal As Long
    retVal = CurrentBalance / MinimumPayment
    AccountInterface_MonthsToPayoff = retVal
End Function

My thought is that there will be one interface but different calculations for the same function across different account types like a credit card vs a car loan.

I also have put some validation already into the user form. I don’t really want to do that. I’m just sort of testing out my thought process so far and will adjust as needed.

Note that the Interface is just a definition of what a class that implements that interface should contain.