Solved

VB Returns an Error 53 (File Not Found) when executing fso.FolderExists but folder exists on the local machine

Posted on 2006-11-13
4
769 Views
Last Modified: 2013-12-26
I have an VB 6.0 application that periodically (once a minute) looks for any text file in a particular folder.  This folder exists on the local machine where the VB application is running.  Folder path is hard coded in an "ini" file at startup.  99% of the time, this function works properly, but about once a month Error 53 (File Not Found) is returned.  It seems to occur for 15-30 minutes, then finds the folder again with no user intervention.

This system pages me 24/7 if the files are not processed, so I would love to figure this one out.  Any ideas?

Here is the code:

Public Function LookForInputFile() As Boolean
    Dim ExtString As String
    Dim PathString As String
    Dim fso2 As New FileSystemObject
    Dim fileExists As Boolean
   
    ExtString = "*.txt"
    PathString = autoDetectFilePath & ExtString
   
    If fso2.FolderExists(autoDetectFilePath) Then
        filAutoDetect.FileName = PathString
        lblAutoDetect.Caption = PathString
        filAutoDetect.Refresh
        If filAutoDetect.ListCount > 0 Then 'file or files found
            LookForInputFile = True
            '
            ' Do some processing based on unique file names
            '
        ElseIf filAutoDetect.ListCount = 0 Then
            LookForInputFile = False
        End If
    Else
        LookForInputFile = False
    End If
End Function
0
Comment
Question by:sainiak
4 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 17931012
Would love to help out...but what exactly is "filAutoDetect"?
0
 

Author Comment

by:sainiak
ID: 17931763
filAutoDetect is a File List Box.  It displays the files in the PathString.
Based in the logging I do, I don't think it is getting that far in the code.  
I think the error is occurring on the "If fso2.FolderExists(autoDetectFilePath) Then" statement.
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 18010758
It isn't clear if where the autoDetectFilePath value comes from.

I would suggest that you write to a log file at strategic points.

Public Function LookForInputFile() As Boolean
    Dim ExtString As String
    Dim PathString As String
    Dim fso2 As New FileSystemObject
    Dim fileExists As Boolean
   
    ExtString = "*.txt"
    PathString = autoDetectFilePath & ExtString
   WriteLog "LookForInputFile: Pathstring = " & PathString
    If fso2.FolderExists(autoDetectFilePath) Then
      WriteLog "LookForInputFile: Folder " & autoDetectFilePath & " found"
      filAutoDetect.FileName = PathString
        lblAutoDetect.Caption = PathString
        filAutoDetect.Refresh
        WriteLog "LookForInputFile:  ListCount = " & filAutoDetect.ListCount
        If filAutoDetect.ListCount > 0 Then 'file or files found

            LookForInputFile = True
            '
            ' Do some processing based on unique file names
            '
        ElseIf filAutoDetect.ListCount = 0 Then
            LookForInputFile = False
        End If
    Else
        LookForInputFile = False
        WriteLog "LookForInputFile: Folder " & autoDetectFilePath & " not found"

    End If
End Function

The built-in logging doesn't work in design mode, so I use one like this:

Sub WriteLog(strText As String)
    Dim strText1 As String
    Dim f As Integer
    Dim strFile As String
    strFile = "C:\Documents and Settings\User Name\My Documents\fil" & Format$(Now, "yyy") & ".Log"
    f = FreeFile
    strText1 = Format$(Now, "hh:nn:ss ") & strText
    Debug.Print strText1
    Open strFile For Append As #f
    Print #f, strText1
    Close #f
End Sub

Also you might like to try a different test for the folder:

If Dir$(autoDetectFilePath, vbDirectory) <> "" Then

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now