Files in a directory

J

Jeffry Montalvo

Hello everyone,
I have created a database and everything is working fine. I just would like
to access directory contents and displayed then in a form. For example I
have records that I have saved/scan to a particular directory now I would
like to see then on the bottom of the form. Can someone help me with this.

Thanks in advance,
JM
 
G

Guest

Allen,
Thank you very much for the direction on this. I also needed a directory
(folder) listing and your instructions were perfect. Everything worked.

Not a huge deal, but if I want to list just the file name(s) and exclude the
path, where would I need to modify the code?

Thanks in advance.
 
D

Douglas J. Steele

In the function FillDir, change

colDirList.Add strFolder & strTemp

to

colDirList.Add strTemp
 
G

Guest

Thanks - that worked. I tried that earlier...guess I flubbed a key or
something. Anyway, one more thing...
The folder listing is just for informational purposes. Once A button is
clicked, the files that are listed are processed and moved to another folder.
Is there a way to "refresh" the listbox after clicking on the button (which
property of which object)?

Thanks again.
 
D

Douglas J. Steele

I didn't look that closely at what Allen's doing on that page. Try:

Me!NameOfListbox.Requery

If that doesn't work, you'll have to requery the files to repopulate the
collection.
 
G

Guest

Thanks Douglas, I'll try it. What I can briefly tell you about Allen's
solution is that he uses nested functions to get this accomplished, so I'm
not sure the requery will work (but haven't tested it yet).

I also tried requerying the files, but that's where I got stuck - didn't
know where (or how) to requery through the module's code.

Thanks again.
 
A

Allen Browne

The code uses AddItem to add the files name to the unbound list box, so it
should not need a requery.

Doug, the code is based on a posting by Albert Kallal.
It adds file names to a collection, calling itself recursively for
subfolders.
The optional list box is a Value List.
 
D

Douglas J. Steele

Okay, I looked at the code again.

To repopulate the listbox after the files have been moved to another
location, it's necessary to call the ListFiles function again. However, it's
also necessary to manually empty the listbox first. This can be accomplished
using:

Me.MyListBox.RowSource = vbNullString

That line of code could be added to the ListFiles function between the
"Else" and "For Each varItem in colDirList" lines.
 
G

Guest

Thanks Doug,
I tried your solution but when compiling, I got the message: "Invalid use of
Me keyword"...

Also, could not find the "MyListBox control, so I used "lst" which is
variable and based on 1 of the 2 list boxes I'm using. So I used
"lst.RowSource = vbNullString" - let's see how that works.

Again, thanks.
 
G

Guest

I have followed this posting because I had the same problem with listing
files from a directory into a list box. Using the advice and examples here I
was able to achieve this. I was also able to get the list box to only show
the file name, not the entire file path.

The problem is that when I changed the FillDir function so that only the
file name was displayed, I can no longer click the file in the list box and
open the file. The code that I am using is as follows:

To open the selected file in the DblClick event of the listbox, I used:
FollowHyperlink Me.rollvaultfilelist

I get a run-time error 490. Is this becuase the alteration to the FillDir
strips out the file path? If so, is there a solution or code work-around?

Thanks to everyone for all the help and examples that are provided in this
forum. Beginners, like myself, could never achieve what I have with out
your help!

Thanks a million!!
 
D

Douglas J. Steele

If you know the folder, you can use FollowHyperlink "E:\Folder\" &
Me.rollvaultfilelist (or whatever the folder is: the critical part is that
it end in a slash)

If you don't know the folder, you're out of luck.
 

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

Similar Threads


Top