[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
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
Medium Priority
?
788 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
3 Comments
 
LVL 86

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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

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…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month19 days, 6 hours left to enroll

834 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