Access JumpStart 2.0 | Blog

A Rapid Development Framework for Microsoft Access

I’m going to start the next test with something simple. A new type of field. I will add a checkbox to the test form and bind it to a Yes/No field and write a test to check to see if it updates the values as expected.

I added the checkbox to the form, added a new Yes/No column on the table, and bound the field to it.

I copied the existing text box change value test and updated it to use the checkbox and boolean values of True and False for the changes to the field:

'@TestMethod("Verify Changes")
Private Sub WhenCheckboxFieldChangesBeforeAndAfterValuesAreReturned()
    Dim dctInputs As New Scripting.Dictionary, colResults As VBA.Collection
    Set dctInputs = CreateAndAddToInputDict(FieldToChange:="TestCheckBoolean", InitialValue:=False, ChangeTo:=True)
    Set colResults = SetFields_ChangeThem_ReturnNewListOfChanges(dctInputs)
    Assert.IsTrue FieldInputsMatchResults(dctInputs, colResults(1).FieldChanges)
End Sub

This compiled fine without errors, Woo-hoo.

Then I ran all the tests. The new test did not pass, failing because it returned an empty collection for colResults.

All right, we got our failing test.

So I started digging into the failure. Turns out in the BeforeUpdate event of the FieldAuditor class we are only checking for text boxes and combo boxes:

Private Sub FormToAudit_BeforeUpdate(Cancel As Integer)
    Dim Fld As Variant, ChangeDictionary As New Scripting.Dictionary, Ctl As Access.Control
    For Each Fld In FormToAudit
        Set Ctl = Fld
        If Ctl.ControlType <> acComboBox And Ctl.ControlType <> acTextBox Then GoTo SkipLoop
        If FieldChanged(Ctl) Then ChangeDictionary.Add Ctl.Name, CreateAuditFieldChange(Ctl)
SkipLoop:
    Next Fld
    If ChangeDictionary.Count > 0 Then pListOfChanges.Add CreateAuditEventDetails(ChangeDictionary)
End Sub

I changed the conditional statements to a case statement for now and added the acCheckBox to the allowed controls to check:

Private Sub FormToAudit_BeforeUpdate(Cancel As Integer)
    Dim Fld As Variant, ChangeDictionary As New Scripting.Dictionary, Ctl As Access.Control
    For Each Fld In FormToAudit
        Set Ctl = Fld
        Select Case Ctl.ControlType
            Case acComboBox, acTextBox, acCheckBox
            Case Else: GoTo SkipLoop
        End Select
        If FieldChanged(Ctl) Then ChangeDictionary.Add Ctl.Name, CreateAuditFieldChange(Ctl)
SkipLoop:
    Next Fld
    If ChangeDictionary.Count > 0 Then pListOfChanges.Add CreateAuditEventDetails(ChangeDictionary)
End Sub

And I tested again. And it surprised me that it passed. Ok. We’ll do another test next time…