Check if file exists

N

Newbie

Hi,

I want to check whether a file exists in a directory before I attempt to
import it

I tried:
if Dir("c:\dira\textfile.txt") then
docmd.transfertext etc
else
msgbox "File does not exist"
end if

But this does not work

How can I check for the existence of a file?

Thanks
 
D

Dirk Goldgar

Newbie said:
Hi,

I want to check whether a file exists in a directory before I attempt
to import it

I tried:
if Dir("c:\dira\textfile.txt") then
docmd.transfertext etc
else
msgbox "File does not exist"
end if

But this does not work

How can I check for the existence of a file?

Thanks

You're close. Try this:

If Len(Dir("c:\dira\textfile.txt")) > 0 Then
docmd.transfertext etc
Else
MsgBox "File does not exist"
End If

Dir() return the file name if it exists, a zero-length string if it
doesn't.
 
N

Newbie

thanks works a treat
Al


Dirk Goldgar said:
You're close. Try this:

If Len(Dir("c:\dira\textfile.txt")) > 0 Then
docmd.transfertext etc
Else
MsgBox "File does not exist"
End If

Dir() return the file name if it exists, a zero-length string if it
doesn't.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 

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