Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

create a query to list files from folder

Status
Not open for further replies.

smuthcrmnl777

Technical User
Jan 16, 2006
104
US
Is it possible to have a query that would list all of the files in a folder location. I would like to build a hyperlink that looks up this list. Please just point me in the right direction.
 
There's VBA code that can do that but not a query. Queries extract data from tables in a database and the files in a directory are not in a table. You can look at the Dir command or the FileSystemObject. Both are capable of returning such a list.

[small]No! No! You're not thinking ... you're only being logical.
- Neils Bohr[/small]
 
Create a listbox on your form. Name it ListFiles. Create a command button. On the OnClick event of the command button, place the following code:

Dim LoadFiles As String
Dim strFill As String
LoadFiles = Dir$("c:\dev\*.*")
Do While LoadFiles > ""
strFill = strFill & LoadFiles & ";"
LoadFiles = Dir$
Loop
ListFiles.RowSource = strFill

Substitute the directories path name in the LoadFiles statement.
The listbox will have a list of filenames.
 
I am not exactly sure I follow with this code. I plugged it into a form like you said and I hit the cmd button and nothing appears in the list box. I then look at the properties of the list box and see all of the files in the row source. Can you tell me why the code does not display the data in the list box?
 
You must be very specific in describing what you did to create the listbox and the names you gave it. When you created the listbox, did you cancel the listbox wizard? You want an unbound listbox. Did you name the listbox ListFiles? This is placed in the Name option on the property sheet of the listbox.
Did you create this in design view, then switch to form view to click the command button?
Remember, I'm not there to watch.

I think I know. Change the Rowsource Type to Value List. Forgot to tell you that. oops.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top