bad file name

M

Mike Archer

Hello all
The following line returns a run time error 52 (bad file
name) occasionally when sName does not exist:

If Dir(sName) <> "" Then

The If block code should be skipped when sName does not
exist, not return an error. The error occurs
sporadically. Most of the time, the code performs as
expected. When the error occurs, it will not repeat in
debug mode (it steps through the line just fine).

Am I doing something wrong with the Dir statement or is
there a more stable way to check for the existence of
sName without creating a lot of overhead?
TIA
Mike
 
T

Tom Ogilvy

Dim sStr as String
sStr = ""
On error resume next
sStr = Dir(sName)
On Error goto 0
if sStr <> "" then
 

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