file names table

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Using A2K, is it possible to import all filenames (and only filenames) from a
folder into a table? I only want the filename and extension, and not the
actual data in the filename. My table will then consist of 1 field, which is
the filename and extension.
I have a folder which consists of many scanned documents. It turns out that
in order to get these documents into a program which can import them for
users to see the actual documents on-demand, I need to create a file of the
document names.
Thanks in advance,
Dan
 
This example will bring all the file names from C: and append into a table
name TableName that has a field named FileName

Try something like:

Function AppendFileName()
Dim fs As Object, FileName As String, Path As String, MyDB As DAO.Database
Dim MyRec As DAO.Recordset

Set MyDB = CurrentDb()
Set MyRec = MyDB.OpenRecordset("Select * From TableName")
Set fs = Application.FileSearch
With fs
.LookIn = "c:\"
.FileName = "*.*"
If .Execute > 0 Then
For I = 1 To .FoundFiles.Count
Path = .FoundFiles(I)
FileName = BuildFileName(.FoundFiles(I))
MyRec.AddNew
MyRec!FileName = FileName
MyRec.Update
Next I
End If
End With

End Function
 
Should this be in a module, and if so how do I call it to populate the table?
I tried the code within the Function behind the Click of a command button
but got an error message Sub or Function not defined for 'BuildFileName'.
Thanks,
Dan
 
Define it under a module, and in the OnClick event of the Button write directly

=AppendFileName()

Or, on the OnClick event select Code view and in the code write

AppendFileName
 
Thanks Ofer,
In the OnClick event I selected Code view and wrote
AppendFileName
I still get the Compile error: 'Sub or Function not defined' pointing to the
statement BuildFileName
in
FileName = BuildFileName(.FoundFiles(I))
I appreciate your help.
Dan
 
Change the code to something like the following to get JUST the file
name:


Function AppendFileName()
Dim fs As Object, FileName As String, Path As String, MyDB As
DAO.Database
Dim MyRec As DAO.Recordset
Dim myLookIn As String
myLookIn = "c:\"

Set MyDB = CurrentDb()
Set MyRec = MyDB.OpenRecordset("Select * From testTable")
Set fs = Application.FileSearch
With fs
.LookIn = myLookIn
.FileName = "*.*"
If .Execute > 0 Then
For i = 1 To .FoundFiles.Count
Path = .FoundFiles(i)
FileName = Mid(.FoundFiles(i), Len(myLookIn) + 1, 250)
MyRec.AddNew
MyRec!FileName = FileName
MyRec.Update
Next i
End If
End With


End Function
 
So Sorry, I missed one function.

You can use Ron's modification to the function to get what you need, keep
in mind that he used another table name
 

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

Back
Top