Verify file exists before executing TransferText

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!
 
O

orange via AccessMonster.com

Zoe said:
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!
I suggest you use the file scripting object and the FileExists method

See http://msdn.microsoft.com/en-us/library/x23stk5t(v=VS.85).aspx

then click on FileExists method for an example

Make sure you include a reference to the scripting runtime.
 
K

Ken Snell

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top