I have read over the help file and dont mind admitting I am a little lost on
how to go about this. From the sounds of it, you are pointing me in the
right direction. I do have a long list of files in different folders I need
to display and would the user to be able to select the one they want.
Currently I am placing all my code behind each button for each file. Can you
help walk me through this process? Thank you in advance for your assistance.
It is indeed a bit tricky - the Dir function is peculiar in that it
"remembers" what was called previously. I have no way to know how your folder
structure is set up or how you want the users to pick folders or files so I
can't give you exact directions. Might the folder be anywhere (C:\Program
Files, C:\Windows, ...????) or is there some parent folder with subfolders?
What are you starting with?
Just as an example to put all the .pdf filenames in the directory
C:\Documents and Settings\John\My Documents\PDFFiles into a Table named
MyFiles with fields FileID (autonumber), Pathname, and Filename, you could use
code like:
' Set the path.
Dim MyPath As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db=CurrentDb
Set rs = db.OpenRecordset("MyFiles") ' open the table
MyPath = "C:\Documents and Settings\John\My Documents\PDFFiles\*.pdf"
MyName = Dir(MyPath) ' Retrieve the first PDF file in that folder.
Do While MyName <> "" ' Start the loop.
rs.AddNew ' add a new record to the MyFiles table
rs!Path = MyPath ' set the value of the path
rs!Filename = MyName ' fill in the current filename
MyName = Dir ' Get next entry.
rs.Update ' actually write the record into the table
Loop
This will loop through all the .pdf files in the chosen directory and write
the name into the file. You will also need to loop through the folders and
subfolders, I presume.