In VBA Ms Access, I import a txt file parsing it line by line.
I use a FileDialog so the user can choose the file to import, but when I open the file to read it, I obtain a runtime error 55 – file already open.
The cose is:
Dim openDialog As FileDialog
Set openDialog = Application.FileDialog(msoFileDialogFilePicker)
On Error GoTo DoNothing
With openDialog
.title = "Import"
.AllowMultiSelect = False
.Show
End With
FName = openDialog.SelectedItems.Item(1)
'Close FName
Open FName For Input Access Read As #1
On Error GoTo DoNothing
Instead, if I use Close Fname, there are no runtime errors, but the import doesn’t work (the code for the import is right, ’cause it works when I hard code the namefile)
once you have the filename, drop the dialog box handler with: