FoundFiles not finding files....

G

Guest

Assume a folder structure of C:\Test, which contains a subfolder called "ABC"
In the C:\Test folder, I have an Access db with a VBA module in it. In the
C:\Test\ABC subfolder I have a number of .csv files.

Can someone tell me what flaw in my logic (or my VBA skills) causes the
running of this code from that module to always return my message, "There
were no files found in C:\Test\ABC" (that is, to be unable to find the .csv
files in the ABC subfolder)?


Dim strPathToDB As String
Dim fs
Dim iCtr As Integer
Dim iNumFiles As Integer

strPathToDB = Application.CurrentProject.Path
Set fs = Application.FileSearch
fs.LookIn = strPathToDB & "\ABC"
fs.FileName = "*.csv"
iNumFiles = fs.FoundFiles.Count
If iNumFiles = 0 Then
MsgBox "There were no files found in " & fs.LookIn
Else
MsgBox "There were " & iNumFiles & "files found in " & fs.LookIn
End If

Thanks.
 
D

David Lloyd

Matthew:

You need to call the Execute method on the FileSearch object after setting
the FileName property. The Execute method invokes the search.


--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.


Assume a folder structure of C:\Test, which contains a subfolder called
"ABC"
In the C:\Test folder, I have an Access db with a VBA module in it. In the
C:\Test\ABC subfolder I have a number of .csv files.

Can someone tell me what flaw in my logic (or my VBA skills) causes the
running of this code from that module to always return my message, "There
were no files found in C:\Test\ABC" (that is, to be unable to find the .csv
files in the ABC subfolder)?


Dim strPathToDB As String
Dim fs
Dim iCtr As Integer
Dim iNumFiles As Integer

strPathToDB = Application.CurrentProject.Path
Set fs = Application.FileSearch
fs.LookIn = strPathToDB & "\ABC"
fs.FileName = "*.csv"
iNumFiles = fs.FoundFiles.Count
If iNumFiles = 0 Then
MsgBox "There were no files found in " & fs.LookIn
Else
MsgBox "There were " & iNumFiles & "files found in " & fs.LookIn
End If

Thanks.
 

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