Importing filenames

Milan

Registered User.
Local time
Today, 06:23
Joined
Feb 17, 2002
Messages
85
Hi People!!

How can i import file names with their extenstions i.e Test.mdb into a unbound list box on a form. I would like to import from a specific folder which has many access mdbs. I need the form to list these mdb's with their names & file ext.


Would appreciate any useful advice!
 
This code populates a table with all files ending in mdb. Amend to suit your purpose. Without changing things you will need to create a table called "Found"with a text field called FileName. You will also need to create a delete query called delFound which deletes all records in table Found.

Function Find_MDB()
DoCmd.SetWarnings False

DoCmd.OpenQuery "delFound"

Set rstMDB = CurrentDb.OpenRecordset("Found", dbOpenDynaset)
With Application.FileSearch
.NewSearch
.LookIn = "c:\"
.SearchSubFolders = True
.FileName = ""
.MatchAllWordForms = True
If .Execute() > 0 Then
For i = 1 To .FoundFiles.Count
If Right(.FoundFiles(i), 3) = "mdb" Then
rstMDB.AddNew
rstMDB("FileName") = .FoundFiles(i)
rstMDB.Update
End If
Next i
Else
MsgBox "There were no files found."
End If
End With
rstMDB.Close

End Function


HTH
 
Last edited:
Hey!Thanks for that - Works a treat!

I have made some minor modifications to suit my form!

Thanks Again!
 

Users who are viewing this thread

Back
Top Bottom