Access JumpStart 2.0 | Blog

A Rapid Development Framework for Microsoft Access

I’m going to add a data element to our collection so that the user of our Form Auditor class will have the bound field name from the ControlSource property. First I will add a new test to check for this additional field in order to have a failing test, then I can write the code to make the test pass. Here goes:

My failing test:

'@TestMethod("Verify Info Fields")
Private Sub WhenFieldChangesAreReturnedInfoContainsControlSource()
    Dim dctInputs As New Scripting.Dictionary, colResults As VBA.Collection
    Set dctInputs = CreateAndAddToInputDict(FieldToChange:="TestText", InitialValue:="BeforeValue", ChangeTo:="AfterValue")
    Set colResults = SetFields_ChangeThem_ReturnNewListOfChanges(dctInputs)
    Assert.IsTrue colResults(1).FieldChanges("TestText").ControlSource = "TestText"
End Sub

The database compiles, and the test fails and produces a Run Time error that ControlSource is not a property of the FieldChanges collection.

Now it should be a simple exercise in adding the ControlSource Property to our AuditFieldChange object. That object is super simple, just containing public variant values, and here I have added the ControlSource property by adding it to the list:

Option Compare Database
Option Explicit

Public OldValue As Variant, NewValue As Variant, ControlSource As Variant

Easy enough. Now I need to populate the ControlSource field in the FormAuditor object. I do that in a function called CreateAuditFieldChange and have added the line needed I think to do that:

Private Function CreateAuditFieldChange(Fld As Access.Control) As AuditFieldChange
    Dim retVal As AuditFieldChange
    Set retVal = New AuditFieldChange
    retVal.OldValue = FormToAudit(Fld.Name).OldValue
    retVal.NewValue = FormToAudit(Fld.Name).Value
    retVal.ControlSource = FormToAudit(Fld.Name).ControlSource
    Set CreateAuditFieldChange = retVal
End Function

This code is still failing, so I’m going to see what is actually being returned. I suspect Access adds an “=” in front of the string or something… I am about to look.

Actually, as I looked, I saw that the test passed. It’s a different test that is not passing. This is the test that I wrote to test whether the field changed by itself, or whether two fields bound to the same data would both trigger the change in the before update. I’ll think about this more in a post on another day.