Strings

G

Guest

here is the function that was given to me from previouse post.
Function LocateFile(strFileName As String)
Dim vItem As Variant
Dim db As DAO.Database
Set db = CurrentDb
With Application.FileSearch
.FileName = strFileName
.LookIn = "N:\Databases\Tech manuals"
.SearchSubFolders = True
.Execute
For Each vItem In .FoundFiles
db.Execute _
"INSERT INTO TBook (BookName) " & _
"VALUES(" & Chr(34) & vItem & Chr(34) & ")", _
dbFailOnError
Next vItem
End With
Set db = Nothing
End Function

Works great, however will not list files in the table that has a .zip file
extension or the folder. for example: I have a file that wont import the
path and the filename N:\Databases\Tech manuals\AutoRepair\AutoRepair.zip

Instead of importing filenames, can I just import the folders. then I can
use the split function. Note on Split Function using Access 2003 in
yesterdays post.

Function GetSecondElement(InputValue As String) As String

GetSecondElement = Split(InputValue, "\")(2)

End Function

Only thing that did work correctly....Great Function!

I can change this function so it returns the value in a query Auto Repair
from the above example by changing the (2) to a (3) etc.

Thanks guys
 
A

Allen Browne

Yes, the FileSearch object does handle zip files inconsistently.

Another good reason not to use it is that it is no supported in Access 2007
(at least not in the current beta.)

Here's an alternative approach:
List files recursively
at:
http://allenbrowne.com/ser-59.html

The code accepts a starting path, and optionally a file spec, subfolder
switch, and can list the files or add them to a list box.

If you are interested in handling folders only, you can probably do that by
writing your code based on the block that starts:
If bIncludeSubfolders Then
 

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