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
765 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…

757 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

20 Experts available now in Live!

Get 1:1 Help Now