Code to list documents

  • Thread starter Thread starter Peter McCartney
  • Start date Start date
P

Peter McCartney

Hello All! Thanking anyone for assistance. A97.

In this directory "c:\training\documents" I store my documents.

How do I code access to look at that directory then store the document names
for use in a listbox.

Peter McCartney
 
To determine all of the documents in the directory, use the Dir function
repeatitively:

Dim strFile As String
Dim strFolder As String

strFolder = "c:\training\documents\"
strFile = Dir(strFolder & "*.*")
Do While Len(strFile) > 0
Debug.Print strFolder & strFile
strFile = Dir()
Loop

To see the files in a list box rather than just printing them to the
Immediate window, you can either store them in a table and have a query
against that table as the RowSource for the list box (with the RowSourceType
set to Table/Query), or you can concatenate them into a string (separating
them with semi-colons) and use that string as the RowSource (with the
RowSourceType set to Value List)

On the other hand, if your intent is to let them select documents from the
list for processing purposes, you could use the standard Windows File Open
dialog. There's complete code to do this as
http://www.mvps.org/access/api/api0001.htm at "The Access Web"
 
Back
Top