DIR() giving odd error

User avatar
Abraxus
3StarLounger
Posts: 254
Joined: 01 Mar 2010, 17:34
Location: Blue Springs, MO

DIR() giving odd error

Post by Abraxus »

I have a list of files I need to validate are on my computer. I'm using this to check if they exist:

Code: Select all

Function DoesFileExist(strFileIN as String) as Boolean
   if Dir(strFileIn) <> "" then
     DoesFileExist = True
   else
     DoesFileExist = False
   End IF
End Function
However, I am getting Run-Time error '53': File not found for the DIR on one of my files instead of going to the False option of the If.

Why would that be and how do I correct it?

Thanks!
Morgan

User avatar
HansV
Administrator
Posts: 78530
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: DIR() giving odd error

Post by HansV »

Perhaps you specified a UNC path that doesn't exist?
Try thus version

Code: Select all

Function DoesFileExist(strFileIN As String) As Boolean
   On Error Resume Next
   If Dir(strFileIN) = "" Then
     DoesFileExist = False
   Else
     DoesFileExist = True
   End If
End Function
Note that I changed the condition too.
Best wishes,
Hans