# FileMustExist
{: .no_toc }

Returns or sets whether the Open dialog lets the user choose only the name of a file that exists.

Syntax: *object*.**FileMustExist** [ = *boolean* ]

*object*
: *required* An object expression that evaluates to a **cDialog**.

*boolean*
: A **Boolean**. **True** sets `OFN_FILEMUSTEXIST`. The default is **True**.

## Remarks

Only [**ShowOpen**](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/ShowOpen.md) uses the property. [**ShowSave**](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/ShowSave.md) never sets `OFN_FILEMUSTEXIST`, and Windows documents the flag for Open dialogs only, so **FileMustExist** has no effect on a Save As dialog. [**ShowBrowseForFolder**](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/ShowBrowseForFolder.md) ignores it too.

With **True**, a name that the user types and that does not exist, such as `nosuch.txt`, makes Windows show the box *File not found. Check the file name and try again.*, and the Open dialog stays open. Windows documents that the flag also applies `OFN_PATHMUSTEXIST`. With **False**, **ShowOpen** returns the path of a file that does not exist, and does not create the file, so the caller has to be ready to meet a missing file.

With [**CreatePrompt**](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/CreatePrompt.md) **True**, the question of that property is asked in place of the box, whether **FileMustExist** is **True** or **False**.

## Example

```tb check_build check_run
Dim dlg As New cDialog
Debug.Print dlg.FileMustExist   ' True

dlg.FileMustExist = False
Debug.Print dlg.FileMustExist   ' False
```

This example lets the Open dialog return a name that does not exist, and creates the file when it is missing.

```tb check_build
Dim dlg As New cDialog
Dim path As String

dlg.FileMustExist = False
path = dlg.ShowOpen()
If Len(path) > 0 Then
    If Len(Dir$(path)) = 0 Then
        Open path For Output As #1
        Close #1
    End If
End If
```

## See Also

- [PathMustExist](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/PathMustExist.md) property -- the check on the folder of the name
- [CreatePrompt](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/CreatePrompt.md) property -- asks before a name that does not exist is accepted
- [ShowOpen](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/ShowOpen.md) method -- shows the Open dialog
- [cDialog](/tB/Packages/Contributed/TBMANLIB_Dialog/cDialog/index.md) class -- overview
