Help with string results

J

Jim

Hello:
I found this function in the MS Knowledge Base to search for files and print
the results to the Immediate window. It works great, but I need to know how
to put the results in a table. I'm new to vba, so any help is greatly
appreciated.

Jim

Function LocateFile(strFileName As String)
Dim vItem As Variant
Dim strFilePath As String

With Application.FileSearch
.FileName = strFileName
.LookIn = "C:\"
.SearchSubFolders = True
.Execute
For Each vItem In .FoundFiles
Debug.Print vItem
Next vItem
End With
End Function
 
A

Allen Browne

At the top of the code, add:
Dim rs As DAO.Recordset
Set rs = dbEngine(0)(0).OpenRecordset("Table1")

In place of the Debug.Print line:
rs.AddNew
rs![Field1] = vItem
rs.Update

At the end of the code, add:
rs.Close
Set Rs = Nothing

Substitute your own table and field names for Table1 and Field1.
 

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