---
style: dd
fqn: modUtil.LogError
file: vba-source/modUtil.bas
icon:
---

# Business Logic — modUtil.LogError() [7 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `modUtil.LogError` |
| Layer | Utility |
| Module | `modUtil` (Package: `vba-source/modUtil.bas`) |

## 1. Role

### modUtil.LogError()

`LogError` is a shared utility method responsible for persisting error records generated during batch import processing. It operates as an append-only audit trail: whenever the calling routine (`modImport.RunImport`) encounters a row-level failure (e.g., data validation error, transformation failure, or database write error), it invokes this method to record the error against the specific batch and row, ensuring no import failure goes silently unreported. The method implements a simple **delegation** pattern — it does not contain business logic of its own but wraps the DAO database write into a reusable, consistently-formatted routine. Its role in the larger system is that of a **logging side-effect**: it is purely a write operation with no return value, and it is called exclusively from the import controller to guarantee every row-level failure is captured with a full timestamp for later review, retry, or reconciliation.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["LogError(batchID, rowNo, msg)"])
    STEP1["Declare DAO.Database db"]
    STEP2["Set db = CurrentDb()"]
    STEP3["Escape single quotes in msg via Replace(msg, \"'\", \"''\")]
    STEP4["INSERT INTO tblErrorLog (BatchID, RowNo, ErrorMsg, [Timestamp]) VALUES (batchID, rowNo, escapedMsg, Now())"]
    STEP5["Set db = Nothing"]
    END_NODE(["Return"])

    START --> STEP1 --> STEP2 --> STEP3 --> STEP4 --> STEP5 --> END_NODE
```

The method executes a linear sequence of steps with no conditional branches:

1. Creates a DAO database object bound to the current Access database.
2. Escapes single quotes in the incoming error message to prevent SQL syntax errors (e.g., a message containing an apostrophe like `it's` becomes `it''s`).
3. Executes an `INSERT` statement against the `tblErrorLog` table, capturing the batch ID, row number, the escaped error message, and the current server timestamp via `Now()`.
4. Releases the database object reference.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| 1 | `batchID` | `Long` | The batch processing run identifier. Correlates the error to a specific import batch (see `tblImportBatch` and `GetNextBatchNumber` for batch lifecycle). All errors logged within the same import run share the same `batchID`. |
| 2 | `rowNo` | `Long` | The 1-based row number within the import file/source that triggered the error. Enables pinpointing exactly which input row caused the failure, supporting error review and corrective re-imports. |
| 3 | `msg` | `String` | The human-readable error description or exception message. Captures diagnostic details (e.g., "Invalid date format in column 3", "Duplicate customer ID 12345"). Single quotes are escaped before storage. |

**External state read:**

| Field | Type | Business Description |
|-------|------|---------------------|
| `CurrentDb()` | DAO.Database reference | Access DAO function returning the current database connection; used to execute the INSERT. |

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| C | `db.Execute` | (direct DAO) | `tblErrorLog` | Create — Appends a new error record to the error log table, recording the batch, row, message, and timestamp. |

This method performs a single **Create** operation: it inserts one row into `tblErrorLog` using DAO's `Execute` method. No SC (Service Component) layer is involved — this is a direct data access call typical of VBA utilities in Access applications. The `tblErrorLog` entity tracks import execution errors and serves as the primary source for error reports and retry workflows.

## 5. Dependency Trace

### Pre-computed evidence from code analysis graph:

No screen/batch entry points found within 8 hops. Direct callers found: 1 methods.
Terminal operations from this method: 1 (tblErrorLog CREATE)

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Module: `modImport` | `RunImport` -> `modUtil.LogError` | `tblErrorLog [C]` |

The sole caller is `modImport.RunImport`, a batch-processing controller that iterates over import file rows and delegates error recording to `LogError`. This utility is not reachable from any screen/form entry point — it is strictly a backend batch utility.

## 6. Per-Branch Detail Blocks

**Block 1** — [PROCEDURAL SEQUENCE] `(straight-line, no branches)` (L24)

> The entire method executes as a linear sequence. No conditions, loops, or error handlers are present.

| # | Type | Code |
|---|------|------|
| 1 | DECL | `Dim db As DAO.Database` | Local DAO database object declaration [-> `DAO.Database`] |
| 2 | SET | `Set db = CurrentDb()` | Initialize database reference to the current Access database |
| 3 | EXEC | `Replace(msg, "'", "''")` | Escape single quotes in error message to prevent SQL syntax issues |
| 4 | CALL | `db.Execute "INSERT INTO tblErrorLog ..."` | Perform the insert into `tblErrorLog` with batchID, rowNo, escaped message, and `Now()` timestamp |
| 5 | SET | `Set db = Nothing` | Release database object reference |
| 6 | RETURN | `(void)` | Exit subroutine (implicit `End Sub`) |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `tblErrorLog` | Table | Error log table — stores per-row failure records from batch import operations. Key fields: BatchID, RowNo, ErrorMsg, Timestamp. |
| `tblImportBatch` | Table | Import batch tracking table — maintains batch run IDs. `GetNextBatchNumber` reads the max BatchID from this table to generate new batch identifiers. |
| `batchID` | Field | Batch identifier — a unique numeric ID assigned to each import run, used to group related error and processing records. |
| `rowNo` | Field | Row number — the 1-based line number of the source data row that caused an error. |
| `DAO` | Acronym | Data Access Objects — Microsoft Access database API used for programmatic data manipulation in VBA. |
| `CurrentDb()` | Method | DAO function that returns a reference to the currently open Access database. |
| `Now()` | Function | VBA function returning the current system date and time; used as the error record's timestamp. |
| `RunImport` | Method | The batch import controller in `modImport` that processes import files row-by-row and delegates error logging to `LogError`. |
