Application.Filesearch in 97

B

Barry M

I am running the following code to check the existence of
a back end database before linking to it:

Dim fs
Set fs = Application.FileSearch
With fs
.LookIn = strDestDbPath
.FileName = strDestDbY
If .Execute() > 0 Then
strYrA = strYrS
Else
strYrA = Format(strYrS) - 1
End If
End With

The problem is that .Execute() is always > 0 (indicating
file is found) even if the file it is searching for does
not exist. The else part never happens.
I thought the code was working in the past.
Am I doing something wrong or is Access possibly corrupted?
Thanking anyone who can enlighten me.
Barry M
 
D

Dirk Goldgar

Barry M said:
I am running the following code to check the existence of
a back end database before linking to it:

Dim fs
Set fs = Application.FileSearch
With fs
.LookIn = strDestDbPath
.FileName = strDestDbY
If .Execute() > 0 Then
strYrA = strYrS
Else
strYrA = Format(strYrS) - 1
End If
End With

The problem is that .Execute() is always > 0 (indicating
file is found) even if the file it is searching for does
not exist. The else part never happens.
I thought the code was working in the past.
Am I doing something wrong or is Access possibly corrupted?
Thanking anyone who can enlighten me.
Barry M

The FileSearch object is a quirky thing. If you're looking in a
particular folder for a specific filename, though, you can find out if
it exists much easier than that. Consider this example:

strDestDbPath = "C:\My Folder"
strDestDbY = "SomeFile.mdb"

If Len(Dir(strDestDbPath & "\" & strDestDbY)) > 0 Then
' The file exists.
strYrA = strYrS
Else
' The file doesn't exist.
strYrA = Format(strYrS) - 1
End If

If you need to search for files that are *like* some specification, or
to search subfolders, post back and we'll see if we can get FileSearch
to work for you or find a better solution.
 
B

Barry M

Thanks, it works a treat.
I only have to check the existence of a specific file in a
specific folder so that is all I need.
Much obliged.
Barry M
 

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