# Business Logic — modImport.BrowseForFile() [10 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `modImport.BrowseForFile` |
| Layer | Utility (VBA standard module) |
| Module | `modImport` (Package: `vba-source/modImport.bas`) |

## 1. Role

### modImport.BrowseForFile()

This method provides a user-facing file selection dialog that allows operators to browse their local filesystem and choose an Excel workbook (.xlsx) for import into the Access database. It acts as a shared UI utility exposed through the `modImport` module — a standard VBA module housing helper routines for the import workflow. The method creates a `FileDialog` object using the `msoFileDialogFilePicker` constant (value 3), configures it to accept only `.xlsx` files, and upon successful user selection, writes the full path of the chosen file into the `txtFilePath` text box on the `frmImport` form. This form field is subsequently consumed by the import process to locate and read the workbook contents. The method implements no business routing, conditional processing, or data persistence of its own — its sole role is to bridge the user's file selection to the import screen. It is typically invoked from a button click event on the import form or from a macro assigned to a form control.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["BrowseForFile()"])
    STEP1["Create FileDialog object"]
    STEP2["Set dialog type = msoFileDialogFilePicker (3)"]
    STEP3["Clear existing filters"]
    STEP4["Add Excel filter: *.xlsx"]
    COND{"User selected file?"}
    STEP5["Assign fd.SelectedItems(1) to frmImport.txtFilePath"]
    STEP6["Release FileDialog object"]
    END(["End Sub"])

    START --> STEP1
    STEP1 --> STEP2
    STEP2 --> STEP3
    STEP3 --> STEP4
    STEP4 --> COND
    COND -->|Yes = -1| STEP5
    COND -->|No: cancelled| STEP6
    STEP5 --> END
    STEP6 --> END
```

**Processing flow:**
1. Declares and instantiates a `FileDialog` object via `Application.FileDialog(3)`, where `3` is the Office constant `msoFileDialogFilePicker` that opens a standard file-browse dialog.
2. Clears any pre-existing file filters so only the configured filter is shown.
3. Adds a single filter labeled "Excel Files" restricted to `*.xlsx` extensions, preventing the user from selecting incompatible file types.
4. Displays the dialog to the user. If the user selects a file and clicks OK, `Show` returns `-1` (`msoModalModal`).
5. When a file is selected, the full path of the first selected item (`fd.SelectedItems(1)`) is written into the `txtFilePath` textbox on the `frmImport` form, making it available to the import routine.
6. Releases the `FileDialog` object reference and exits.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| - | (none) | - | - |

The method accepts no parameters and returns no value (`Sub`). It relies entirely on UI state:

| Source | Type | Business Description |
|--------|------|---------------------|
| `Application.FileDialog(3)` | Office Object | Microsoft Office dialog host that presents the OS-native file picker. The `3` corresponds to `msoFileDialogFilePicker`. |
| `frmImport!txtFilePath` | Form Control | The target text box on the `frmImport` Access form where the selected file path is stored for downstream import processing. |

## 4. CRUD Operations / Called Services

This method performs no database reads, writes, or service component invocations. It is a pure UI helper.

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | - | - | - | No CRUD operations — this method only interacts with the UI (FileDialog and form controls). |

## 5. Dependency Trace

No callers were found in the codebase that reference `BrowseForFile`. The method is likely invoked directly as a form button's `OnClick` event handler or via a macro assigned to the `frmImport` screen control, rather than through a programmatically callable path from other VBA modules.

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | frmImport (Form) | `frmImport` button event -> `modImport.BrowseForFile` | No database terminal (UI only) |

## 6. Per-Branch Detail Blocks

**Block 1** — [SET] `(Object creation)` (L106)

> Declares the `FileDialog` object and configures it for file picking.

| # | Type | Code |
|---|------|------|
| 1 | SET | `Dim fd As Object` |
| 2 | SET | `Set fd = Application.FileDialog(3)` `// 3 = msoFileDialogFilePicker — opens OS file browser dialog` |

**Block 2** — [EXEC] `(Filter configuration)` (L107-108)

> Clears any existing filters and adds the Excel-only filter.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `fd.Filters.Clear` `// Remove all pre-configured file type filters` |
| 2 | EXEC | `fd.Filters.Add "Excel Files", "*.xlsx"` `// Add single filter: only .xlsx files visible to user` |

**Block 3** — [IF] `(User selected a file — fd.Show = -1)` (L109-111)

> The file dialog's `Show` method returns `-1` if the user clicked OK with a selection, or `0` if they cancelled. When a file is selected, its full path is captured.

| # | Type | Code |
|---|------|------|
| 1 | SET | `Forms!frmImport!txtFilePath.Value = fd.SelectedItems(1)` `// Write selected file's full path to the form's txtFilePath text box` |

**Block 4** — [ELSE / fallthrough] `(User cancelled dialog — fd.Show <> -1)` (L109)

> When the user clicks Cancel or closes the dialog, no action is taken — the method skips the assignment and proceeds to cleanup.

| # | Type | Code |
|---|------|------|
| 1 | (no-op) | *(conditional body not entered — form field remains unchanged)* |

**Block 5** — [EXEC] `(Resource cleanup)` (L113)

> Releases the `FileDialog` COM object reference.

| # | Type | Code |
|---|------|------|
| 1 | SET | `Set fd = Nothing` `// Release the FileDialog object to free resources` |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `modImport` | Module | VBA standard module housing import-related utility procedures, including file browsing and batch import orchestration. |
| `frmImport` | Form | Microsoft Access form providing the user interface for file import operations. Contains the `txtFilePath` textbox where the selected file path is stored. |
| `txtFilePath` | Field | Text box control on `frmImport` that holds the full filesystem path of the Excel workbook selected for import. Consumed by the import logic to open and parse the workbook. |
| `msoFileDialogFilePicker` | Constant | Office constant (value 3) specifying that the `FileDialog` should render as a file-selection dialog. |
| `.xlsx` | File type | Microsoft Excel Open XML spreadsheet format — the only file type accepted by the import dialog. |
| `fd.SelectedItems(1)` | Property | Zero-based (one-based in VB6/VBA) collection property returning the full path(s) of files the user selected in the dialog. Index 1 is the first selected file. |
