Verify file exists before executing TransferText

  • Thread starter Thread starter Zoe Norleen
  • Start date Start date
Z

Zoe Norleen

How can I verify that a file exists before I execute the TransferText. I
would like a message to display if the file that I am trying to import does
not exist.

Here is my command:
DoCmd.TransferText acImportDelim, _
"Dailyrpt Import Specification", _
"Dailyrpt", _
[Forms]![Menu]![Path2] & "/dailyrpt.txt"

It works perfectly as long as the dailyrpt.txt file is present. If the file
isn't there, the user needs to know that via a message.

Thanks!
 
Try this (are you sure about the use of the / character in the path and
filename string???):

If Dir([Forms]![Menu]![Path2] & "/dailyrpt.txt") <> "" Then
DoCmd.TransferText acImportDelim, _
"Dailyrpt Import Specification", _
"Dailyrpt", _
[Forms]![Menu]![Path2] & "/dailyrpt.txt"
Else
MsgBox "Text file does not exist"
End If
 
Back
Top