﻿# DN Form Parity Report

Generated: 2026-06-29 08:43

**Original:** `C:\Users\josh\Documents\projects\sync_coordinator\scripts\..\AnniesApp.bak_pre_sql_20260625_234912.mdb`
**Current:** `C:\Users\josh\Documents\projects\sync_coordinator\scripts\..\AnniesApp.mdb`

## Handler comparison - Form_frmDN

| Handler | Status | Notes |
|---------|--------|-------|
| `btnClear_Click` | odbc_transport_rewrite | ODBC-safe rewrite; business triggers preserved |
| `btnDisc_Click` | odbc_transport_rewrite | ODBC-safe rewrite; business triggers preserved |
| `btnSet_Click` | odbc_transport_rewrite | ODBC-safe rewrite; business triggers preserved |
| `CalcDNTotal` | parity_restored | Parity fix applied |
| `cmbCustomer_AfterUpdate` | odbc_transport_rewrite | ODBC-safe rewrite; business triggers preserved |
| `Form_AfterUpdate` | parity_restored | Parity fix applied |
| `Form_BeforeUpdate` | identical | Exact match (normalized whitespace) |
| `Form_Current` | parity_restored | Parity fix applied |
| `Form_Load` | differs | Differs - review subs in appendix |

## Handler comparison - Form_frmDN_With_Con

| Handler | Status | Notes |
|---------|--------|-------|
| `btnClear_Click` | odbc_transport_rewrite | ODBC-safe rewrite; business triggers preserved |
| `btnDisc_Click` | odbc_transport_rewrite | ODBC-safe rewrite; business triggers preserved |
| `btnSet_Click` | odbc_transport_rewrite | ODBC-safe rewrite; business triggers preserved |
| `CalcDNTotal` | parity_restored | Parity fix applied |
| `cmbCustomer_AfterUpdate` | odbc_transport_rewrite | ODBC-safe rewrite; business triggers preserved |
| `Form_AfterUpdate` | parity_restored | Parity fix applied |
| `Form_BeforeUpdate` | identical | Exact match (normalized whitespace) |
| `Form_Current` | parity_restored | Parity fix applied |
| `Form_Load` | differs | Differs - review subs in appendix |

## mdDaoSql parity checks

- [PASS] No ApplyCustomerDeliveryNoteChange helper in mdDaoSql
- [PASS] No RenumberCustomerDeliveryNotes helper in mdDaoSql
- [PASS] SyncInvoiceItems allows deliveryNoteId=0

## Automated code verification (2026-06-29 08:43)

- [PASS] CalcDNTotal calls SyncInvoiceItemsForDeliveryNote (incl. ID=0)
- [PASS] No CalcDNTotal early exit on ID=0
- [PASS] cmbSearch.Requery in Form_Current
- [PASS] No Form_Current new-record fast path
- [PASS] lngCustomerID=0 on new DN in Form_Current
- [PASS] Form_AfterUpdate post-save dblCommission UPDATE
- [PASS] No dblCommission in Form_BeforeUpdate
- [PASS] Inline cmbCustomer renumber via Execute (no helper)
- [PASS] No ApplyCustomerDeliveryNoteChange in frmDN
- [PASS] No dynaset Edit on tblDeliveryNote
- [PASS] No corrupt tblDeliveryNote.txtDeliveryNoteID column refs

**Automated checks: 11 / 11 passed.**

UI smoke scenarios require interactive Access testing against SQL Express.

## Manual smoke test matrix

| # | Scenario | Result | Notes |
|---|----------|--------|-------|
| 1 | Open Delivery Notes (new DN) | manual_required | Code prereqs: 11/11 auto PASS |
| 2 | Select customer on new DN | manual_required | Code prereqs: 11/11 auto PASS |
| 3 | Save new DN | manual_required | Code prereqs: 11/11 auto PASS |
| 4 | Add line item + change dates | manual_required | Code prereqs: 11/11 auto PASS |
| 5 | Open existing invoiced DN | manual_required | Code prereqs: 11/11 auto PASS |
| 6 | Change customer on saved DN | manual_required | Code prereqs: 11/11 auto PASS |
| 7 | btnClear / btnDisc / btnSet | manual_required | Code prereqs: 11/11 auto PASS |
| 8 | Cancel DN (with/without invoice) | manual_required | Code prereqs: 11/11 auto PASS |
| 9 | Invoiced DN - edit line item | manual_required | Code prereqs: 11/11 auto PASS |
| 10 | Browse between saved DNs | manual_required | Code prereqs: 11/11 auto PASS |
| 11 | Unlock (password 2102) | manual_required | Code prereqs: 11/11 auto PASS |
| 12 | Print | manual_required | Code prereqs: 11/11 auto PASS |

## Appendix - original vs current subs (Form_frmDN)

### btnClear_Click (original)
```vba
Private Sub btnClear_Click()
   Dim strSQL As String
   Dim rst As Recordset
   Dim dblTemp As Double
   Dim lngDays As Long
   If MsgBox("Are you sure you want to clear all the return dates for this delivery note?", vbQuestion + vbYesNo, "Clear") = vbYes Then
      If frmDN_Sub.Form.AllowEdits = False Then
         btnUnlock_Click
      End If
      If frmDN_Sub.Form.AllowEdits = True Then
         lngDays = RoundUp(DateDiff("d", txtDateOut, txtDateIn) / conDNDays)
         Set rst = CurrentDb.OpenRecordset("tblSystem", dbOpenSnapshot)
         If Not rst.EOF Then
            dblTemp = rst.Fields("dblPercent")
         Else
            dblTemp = 0.2
         End If
         rst.Close
         strSQL = "SELECT * From tblDeliveryNoteItem WHERE refDeliveryNoteID = " & Nz(DeliveryNoteID, 0)
         Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
         While Not rst.EOF
            rst.Edit
            rst.Fields("strDateIn") = ""
            rst.Fields("dblDiscount") = 0
            rst.Fields("intDays") = lngDays
            rst.Fields("dblAmount") = rst.Fields("dblDailyRate") * lngDays
            If rst.Fields("blnLost") Then
               rst.Fields("dblAmount") = rst.Fields("dblAmount") + (rst.Fields("dblAmount") + (dblTemp * rst.Fields("dblReplaceValue")))
            End If
            rst.Update
            rst.MoveNext
         Wend
         rst.Close
         frmDN_Sub.Requery
         CalcDNTotal
      End If
   End If
End Sub
```

### btnClear_Click (current)
```vba
Private Sub btnClear_Click()
   Dim strSQL As String
   Dim rst As Recordset
   Dim dblTemp As Double
   Dim lngDays As Long
   Dim dblAmt As Double
   If MsgBox("Are you sure you want to clear all the return dates for this delivery note?", vbQuestion + vbYesNo, "Clear") = vbYes Then
      If frmDN_Sub.Form.AllowEdits = False Then
         btnUnlock_Click
      End If
      If frmDN_Sub.Form.AllowEdits = True Then
         lngDays = RoundUp(DateDiff("d", txtDateOut, txtDateIn) / conDNDays)
         dblTemp = SystemPercentLost()
         strSQL = "SELECT DeliveryNoteItemID, dblDailyRate, blnLost, dblReplaceValue FROM tblDeliveryNoteItem WHERE refDeliveryNoteID = " & Nz(txtDeliveryNoteID, 0)
         Set rst = OpenRs(strSQL, dbOpenSnapshot)
         While Not rst.EOF
            dblAmt = rst.Fields("dblDailyRate") * lngDays
            If rst.Fields("blnLost") Then
               dblAmt = dblAmt + (dblAmt + (dblTemp * rst.Fields("dblReplaceValue")))
            End If
            ExecuteSql "UPDATE tblDeliveryNoteItem SET strDateIn = '', dblDiscount = 0, intDays = " & lngDays & ", dblAmount = " & dblAmt & " WHERE DeliveryNoteItemID = " & rst.Fields("DeliveryNoteItemID")
            rst.MoveNext
         Wend
         rst.Close
         frmDN_Sub.Requery
         CalcDNTotal
      End If
   End If
End Sub
```

### btnDisc_Click (original)
```vba
Private Sub btnDisc_Click()
   Dim rst As Recordset
   Dim rst2 As Recordset
   Dim strSQL As String
   Dim dblRate As Double
   Dim intDays As Integer
   Dim dblReplace As Double
   Dim dblTotal As Double
   Dim dblTemp As Double
   
   If (IsNull(txtDisc) = False) And (txtDisc <> "") Then
      strSQL = "SELECT * From tblDeliveryNoteItem WHERE refDeliveryNoteID = " & Nz(DeliveryNoteID, 0)
      Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
      While Not rst.EOF
         rst.Edit
         rst.Fields("dblDiscount") = txtDisc
         dblRate = rst.Fields("dblDailyRate")
         intDays = rst.Fields("intDays")
         dblReplace = rst.Fields("dblReplaceValue")
         dblTotal = dblRate * intDays
         If rst.Fields("blnLost") Then
            Set rst2 = CurrentDb.OpenRecordset("tblSystem", dbOpenSnapshot)
            If Not rst2.EOF Then
               dblTemp = dblTotal * rst2.Fields("dblPercent")
            Else
               dblTemp = dblTotal * 0.2
            End If
            rst2.Close
            dblTotal = dblTotal + dblTemp + dblReplace
         End If
         dblTotal = dblTotal - (dblTotal * txtDisc)
         rst.Fields("dblAmount") = dblTotal
         rst.Update
      rst.MoveNext
      Wend
      rst.Close
      frmDN_Sub.Requery
      CalcDNTotal
   Else
      MsgBox "Please enter a valid percentage!"
   End If
End Sub
```

### btnDisc_Click (current)
```vba
Private Sub btnDisc_Click()
   Dim rst As Recordset
   Dim strSQL As String
   Dim dblRate As Double
   Dim intDays As Integer
   Dim dblReplace As Double
   Dim dblTotal As Double
   Dim dblTemp As Double
   Dim dblAmt As Double
   If (IsNull(txtDisc) = False) And (txtDisc <> "") Then
      strSQL = "SELECT DeliveryNoteItemID, dblDailyRate, intDays, dblReplaceValue, blnLost FROM tblDeliveryNoteItem WHERE refDeliveryNoteID = " & Nz(txtDeliveryNoteID, 0)
      Set rst = OpenRs(strSQL, dbOpenSnapshot)
      While Not rst.EOF
         dblRate = rst.Fields("dblDailyRate")
         intDays = rst.Fields("intDays")
         dblReplace = rst.Fields("dblReplaceValue")
         dblTotal = dblRate * intDays
         If rst.Fields("blnLost") Then
            dblTemp = dblTotal * SystemPercentLost()
            dblTotal = dblTotal + dblTemp + dblReplace
         End If
         dblTotal = dblTotal - (dblTotal * txtDisc)
         ExecuteSql "UPDATE tblDeliveryNoteItem SET dblDiscount = " & txtDisc & ", dblAmount = " & dblTotal & " WHERE DeliveryNoteItemID = " & rst.Fields("DeliveryNoteItemID")
         rst.MoveNext
      Wend
      rst.Close
      frmDN_Sub.Requery
      CalcDNTotal
   Else
      MsgBox "Please enter a valid percentage!"
   End If
End Sub
```

### btnSet_Click (original)
```vba
Private Sub btnSet_Click()
   Dim lngDays As Long
   Dim dblDiscount As Double
   Dim strSQL As String
   Dim rst As Recordset
   If MsgBox("Are you sure you want to set all the blank return dates to the main return date?", vbQuestion + vbYesNo) = vbYes Then
      If frmDN_Sub.Form.AllowEdits = False Then
         btnUnlock_Click
      End If
      If frmDN_Sub.Form.AllowEdits = True Then
         lngDays = DateDiff("d", txtDateOut, txtDateIn)
         If (lngDays <= 1) And (lngDays <> 0) Then
            Set rst = CurrentDb.OpenRecordset("tblSystem", dbOpenSnapshot)
            If Not rst.EOF Then
               dblDiscount = Nz(rst.Fields("dbl24Discount"), 0.5)
            Else
               dblDiscount = 0.5
            End If
            rst.Close
            lngDays = RoundUp(lngDays / conDNDays)
            strSQL = "SELECT * From tblDeliveryNoteItem WHERE ((strDateIn = '') or (strDateIn = Null)) and refDeliveryNoteID = " & DeliveryNoteID
            Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
            While Not rst.EOF
               rst.Edit
               rst.Fields("dblDiscount") = dblDiscount
               rst.Fields("dblAmount") = rst.Fields("dblAmount") - (rst.Fields("dblamount") * dblDiscount)
               rst.Fields("strDateIn") = txtDateIn
               rst.Fields("intDays") = lngDays
               rst.Update
               rst.MoveNext
            Wend
            rst.Close
         Else
            lngDays = RoundUp(lngDays / conDNDays)
            CurrentDb.Execute "Update tblDeliveryNoteItem set strDateIn = '" & Form_frmDN.txtDateIn & "', intDays = " & lngDays & " WHERE ((strDateIn = '') or (Isnull(strDateIn)=True)) and refDeliveryNoteID = " & DeliveryNoteID
         End If
         frmDN_Sub.Requery
         CalcDNTotal
      End If
   End If
End Sub
```

### btnSet_Click (current)
```vba
Private Sub btnSet_Click()
   Dim lngDays As Long
   Dim dblDiscount As Double
   Dim strSQL As String
   Dim rst As Recordset
   Dim dblAmt As Double
   If MsgBox("Are you sure you want to set all the blank return dates to the main return date?", vbQuestion + vbYesNo) = vbYes Then
      If frmDN_Sub.Form.AllowEdits = False Then
         btnUnlock_Click
      End If
      If frmDN_Sub.Form.AllowEdits = True Then
         lngDays = DateDiff("d", txtDateOut, txtDateIn)
         If (lngDays <= 1) And (lngDays <> 0) Then
            dblDiscount = SystemDiscount24h()
            lngDays = RoundUp(lngDays / conDNDays)
            strSQL = "SELECT DeliveryNoteItemID, dblAmount FROM tblDeliveryNoteItem WHERE ((strDateIn = '') OR (strDateIn Is Null)) AND refDeliveryNoteID = " & Nz(txtDeliveryNoteID, 0)
            Set rst = OpenRs(strSQL, dbOpenSnapshot)
            While Not rst.EOF
               dblAmt = rst.Fields("dblAmount") - (rst.Fields("dblAmount") * dblDiscount)
               ExecuteSql "UPDATE tblDeliveryNoteItem SET dblDiscount = " & dblDiscount & ", dblAmount = " & dblAmt & ", strDateIn = '" & Replace(txtDateIn, "'", "''") & "', intDays = " & lngDays & " WHERE DeliveryNoteItemID = " & rst.Fields("DeliveryNoteItemID")
               rst.MoveNext
            Wend
            rst.Close
         Else
            lngDays = RoundUp(lngDays / conDNDays)
            ExecuteSql "UPDATE tblDeliveryNoteItem SET strDateIn = '" & Replace(Form_frmDN.txtDateIn, "'", "''") & "', intDays = " & lngDays & " WHERE ((strDateIn = '') OR (IsNull(strDateIn)=True)) AND refDeliveryNoteID = " & Nz(txtDeliveryNoteID, 0)
         End If
         frmDN_Sub.Requery
         CalcDNTotal
      End If
   End If
End Sub
```

### CalcDNTotal (original)
```vba
Public Sub CalcDNTotal()
   Dim rst As Recordset
   Dim dblTemp As Double
   Dim dblVat As Double
   Dim strSQL As String
   txtSubtotal = 0
   strSQL = "SELECT Sum([dblAmount]) as theSum From tblDeliveryNoteItem WHERE refDeliveryNoteID = " & Nz(txtDeliveryNoteID, 0) & ";"
   Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenSnapshot)
   If Not rst.EOF Then
      txtSubtotal = Nz(rst.Fields("theSum"), 0)
   End If
   rst.Close
   txtSubtotal = txtSubtotal + Nz(txtCleaning, 0) + Nz(txtPackagingFees, 0)
   Set rst = CurrentDb.OpenRecordset("tblSystem", dbOpenSnapshot)
   If Not rst.EOF Then
      dblVat = Nz(rst.Fields("dblVAT"), 0.15)
   Else
      dblVat = Nz(rst.Fields("dblVAT"), 0.15)
   End If
   rst.Close
   
   dblTemp = txtSubtotal
   txtVat = dblTemp * dblVat
   txtTotal = dblTemp + txtVat
   
'consumable total
'   txtTotalCon = 0
'   txtSubtotalCon = 0
'   strSQL = "SELECT Sum([dblTotalExcl]) as theSum From tblDeliveryNoteItemCon WHERE refDeliveryNoteID = " & Nz(txtDeliveryNoteID, 0) & ";"
'   Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenSnapshot)
'   If Not rst.EOF Then
'      txtSubtotalCon = Nz(rst.Fields("theSum"), 0)
'   End If
'   rst.Close
'   dblTemp = txtSubtotalCon
'   txtVatCon = dblTemp * dblVat
'   txtTotalCon = Round(dblTemp + txtVatCon, 2)
'
''grand total
'   dblTemp = txtSubtotal + txtSubtotalCon
'   txtSubtotalGrand = txtSubtotal + txtSubtotalCon
'   txtVatGrand = dblTemp * dblVat
'   txtTotalGrand = Round(dblTemp + txtVatGrand, 2)
   
   CurrentDb.Execute "Update tblInvoiceItem set dblAmount = " & dblTemp & " WHERE refDeliveryNoteID = " & Nz(txtDeliveryNoteID, 0)
   If (IsNull(txtDeliveryNoteID) = False) And ([blnCanceled] = False) Then
      strSQL = "SELECT Sum([dblReplaceValue]) as theSum From tblDeliveryNoteItem WHERE refDeliveryNoteID = " & Nz(txtDeliveryNoteID, 0) & ";"
      Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenSnapshot)
      If Not rst.EOF Then
         dblTemp = Nz(rst.Fields("theSum"), 0)
      Else
         dblTemp = 0
      End If
      rst.Close
      If Me.AllowEdits Then
         txtChequeAmount = dblTemp
      End If
   End If
   CalcHangers
End Sub
```

### CalcDNTotal (current)
```vba
Public Sub CalcDNTotal()
   Dim rst As Recordset
   Dim dblTemp As Double
   Dim dblVat As Double
   Dim strSQL As String
   Dim echoWasOff As Boolean

   echoWasOff = Not Application.Echo
   Application.Echo False

   txtSubtotal = 0
   strSQL = "SELECT Sum([dblAmount]) as theSum From tblDeliveryNoteItem WHERE refDeliveryNoteID = " & Nz(txtDeliveryNoteID, 0) & ";"
   Set rst = OpenRs(strSQL, dbOpenSnapshot)
   If Not rst.EOF Then
      txtSubtotal = Nz(rst.Fields("theSum"), 0)
   End If
   rst.Close
   txtSubtotal = txtSubtotal + Nz(txtCleaning, 0) + Nz(txtPackagingFees, 0)
   Set rst = OpenRs("tblSystem", dbOpenSnapshot)
   If Not rst.EOF Then
      dblVat = Nz(rst.Fields("dblVAT"), 0.15)
   Else
      dblVat = 0.15
   End If
   rst.Close

   dblTemp = txtSubtotal
   txtVat = dblTemp * dblVat
   txtTotal = dblTemp + txtVat

   SyncInvoiceItemsForDeliveryNote Nz(txtDeliveryNoteID, 0), dblTemp

   If (IsNull(txtDeliveryNoteID) = False) And ([blnCanceled] = False) Then
      strSQL = "SELECT Sum([dblReplaceValue]) as theSum From tblDeliveryNoteItem WHERE refDeliveryNoteID = " & Nz(txtDeliveryNoteID, 0) & ";"
      Set rst = OpenRs(strSQL, dbOpenSnapshot)
      If Not rst.EOF Then
         dblTemp = Nz(rst.Fields("theSum"), 0)
      Else
         dblTemp = 0
      End If
      rst.Close
      If Me.AllowEdits Then
         txtChequeAmount = dblTemp
      End If
   End If
   CalcHangers
   If Not echoWasOff Then Application.Echo True
End Sub
```

### cmbCustomer_AfterUpdate (original)
```vba
Private Sub cmbCustomer_AfterUpdate()
   Dim rst As Recordset
   Dim strSQL As String
   'DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
   If cmbCustomer <> lngCustomerID Then
      strSQL = "SELECT Count(*) as theCount From tblDeliveryNote WHERE refCustomerID = " & Nz(cmbCustomer, 0) & " AND DeliveryNoteID <> " & Nz(txtDeliveryNoteID, 0) & ";"
      Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenSnapshot)
      If Not rst.EOF Then
         txtOrderNr = rst.Fields("theCount") + 1
      End If
      rst.Close
      strSQL = "SELECT * From tblDeliveryNote WHERE refCustomerID = " & lngCustomerID & " Order By lngOrderNr;"
      Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
      While Not rst.EOF
         rst.Edit
         rst.Fields("lngOrderNr") = rst.AbsolutePosition + 1
         rst.Update
         rst.MoveNext
      Wend
      rst.Close
   End If
End Sub
```

### cmbCustomer_AfterUpdate (current)
```vba
Private Sub cmbCustomer_AfterUpdate()
   Dim rst As DAO.Recordset
   Dim strSQL As String
   Dim n As Long

   If Nz(cmbCustomer, 0) <> Nz(lngCustomerID, 0) Then
      strSQL = "SELECT Count(*) AS theCount FROM tblDeliveryNote " & _
               "WHERE refCustomerID = " & Nz(cmbCustomer, 0) & _
               " AND DeliveryNoteID <> " & Nz(txtDeliveryNoteID, 0)
      Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenSnapshot, dbSeeChanges)
      If Not rst.EOF Then
         txtOrderNr = Nz(rst.Fields("theCount").Value, 0) + 1
      End If
      rst.Close

      strSQL = "SELECT DeliveryNoteID, lngOrderNr FROM tblDeliveryNote " & _
               "WHERE refCustomerID = " & lngCustomerID & _
               " ORDER BY lngOrderNr, DeliveryNoteID"
      Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenSnapshot, dbSeeChanges)
      n = 0
      Do While Not rst.EOF
         n = n + 1
         If Nz(rst.Fields("lngOrderNr").Value, 0) <> n Then
            CurrentDb.Execute "UPDATE tblDeliveryNote SET lngOrderNr = " & n & _
                              " WHERE DeliveryNoteID = " & CLng(rst.Fields("DeliveryNoteID").Value), dbSeeChanges
         End If
         rst.MoveNext
      Loop
      rst.Close
   End If
End Sub
```

### Form_AfterUpdate (original)
```vba
Private Sub Form_AfterUpdate()
   Dim s As String
   Dim rst As Recordset
   Dim val As Double
   val = 0
   s = "SELECT dblCommission FROM tblSalesPerson WHERE strDescription = """ & txtSalesPerson & """ "
   Set rst = CurrentDb.OpenRecordset(s, dbOpenSnapshot)
   If Not rst.EOF Then
      val = Nz(rst.Fields("dblCommission"), 0)
   End If
   rst.Close
   s = "UPDATE tblDeliveryNote SET dblCommission = " & val & " WHERE DeliveryNoteID = " & DeliveryNoteID & " "
   CurrentDb.Execute s
End Sub
```

### Form_AfterUpdate (current)
```vba
Private Sub Form_AfterUpdate()
   Dim val As Double
   Dim echoWasOff As Boolean
   val = SalesPersonCommission(Nz(txtSalesPerson, ""))
   ExecuteSql "UPDATE tblDeliveryNote SET dblCommission = " & val & _
              " WHERE DeliveryNoteID = " & Nz(txtDeliveryNoteID, 0)
   echoWasOff = Not Application.Echo
   Application.Echo False
   cmbSearch.Requery
   If Not echoWasOff Then Application.Echo True
End Sub
```

### Form_BeforeUpdate (original)
```vba
(not found)
```

### Form_BeforeUpdate (current)
```vba
(not found)
```

### Form_Current (original)
```vba
Private Sub Form_Current()
   Dim rst As Recordset
   Dim strSQL As String
   strSQL = "SELECT * From tblInvoiceItem WHERE refDeliveryNoteID = " & Nz(DeliveryNoteID, 0)
   Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenSnapshot)
   If Not rst.EOF Then
      rst.MoveFirst
      txtInvoiced = "INVOICE:"
      While Not rst.EOF
         txtInvoiced = txtInvoiced & "  " & rst.Fields("refInvoiceID")
         rst.MoveNext
      Wend
      txtInvoiced.ForeColor = vbGreen
   Else
      txtInvoiced = "NOT INVOICED"
      txtInvoiced.ForeColor = vbRed
   End If
   rst.Close
   If txtDeliveryNoteID > 0 Then
      lngCustomerID = Nz(cmbCustomer, 0)
      blnNew = False
   Else
      lngCustomerID = 0
      blnNew = True
   End If
   If chkCanceled Then
      MySetForm False
   Else
      MySetForm True
   End If
   If txtDeliveryNoteID > 0 Then
      strSQL = "SELECT * From UsysDN WHERE lngDNID = " & txtDeliveryNoteID
      Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenSnapshot)
      If rst.EOF Then
         If chkCanceled = False Then
            MySetForm False
         End If
      Else
         If chkCanceled = False Then
            MySetForm True
         End If
      End If
      rst.Close
   Else
      MySetForm True
   End If
   CalcDNTotal
   cmbSearch.Requery
End Sub
```

### Form_Current (current)
```vba
Private Sub Form_Current()
   Static inCurrent As Boolean
   Dim rst As Recordset
   Dim strSQL As String
   Dim echoWasOff As Boolean

   If inCurrent Then Exit Sub
   inCurrent = True

   strSQL = "SELECT * From tblInvoiceItem WHERE refDeliveryNoteID = " & Nz(txtDeliveryNoteID, 0)
   Set rst = OpenRs(strSQL, dbOpenSnapshot)
   If Not rst.EOF Then
      rst.MoveFirst
      txtInvoiced = "INVOICE:"
      While Not rst.EOF
         txtInvoiced = txtInvoiced & "  " & rst.Fields("refInvoiceID")
         rst.MoveNext
      Wend
      txtInvoiced.ForeColor = vbGreen
   Else
      txtInvoiced = "NOT INVOICED"
      txtInvoiced.ForeColor = vbRed
   End If
   rst.Close

   If Nz(txtDeliveryNoteID, 0) > 0 Then
      lngCustomerID = Nz(cmbCustomer, 0)
      blnNew = False
   Else
      lngCustomerID = 0
      blnNew = True
   End If

   If chkCanceled Then
      MySetForm False
   Else
      MySetForm True
   End If

   If Nz(txtDeliveryNoteID, 0) > 0 Then
      strSQL = "SELECT * From UsysDN WHERE lngDNID = " & txtDeliveryNoteID
      Set rst = OpenRs(strSQL, dbOpenSnapshot)
      If rst.EOF Then
         If chkCanceled = False Then
            MySetForm False
         End If
      Else
         If chkCanceled = False Then
            MySetForm True
         End If
      End If
      rst.Close
   Else
      MySetForm True
   End If

   CalcDNTotal

   echoWasOff = Not Application.Echo
   Application.Echo False
   cmbSearch.Requery
   If Not echoWasOff Then Application.Echo True

   inCurrent = False
End Sub
```

### Form_Load (original)
```vba
Private Sub Form_Load()
   CurrentDb.Execute "DELETE * From UsysDN;"
   DoCmd.GoToRecord acDataForm, Me.Name, acNewRec
End Sub
```

### Form_Load (current)
```vba
Private Sub Form_Load()
   On Error Resume Next
   CurrentDb.Execute "DELETE FROM UsysDN"
   On Error GoTo 0
   Me.TimerInterval = 50
End Sub
```

