display directory folder in listbox

brsawvel

Registered User.
Local time
Today, 13:29
Joined
Sep 19, 2007
Messages
256
Hello,

I am recycling the following code for my use:

Code:
[COLOR=black][FONT=Verdana]Private Sub Form_Open(Cancel As Integer)[/FONT][/COLOR]
 
[FONT=Verdana][COLOR=black]Dim strFile As String, strRowSource As String[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]strFile = Dir("C:\MY FOLDER NAME\")[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]strRowSource = strRowSource & strFile[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]Do Until strFile = ""[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]strFile = Dir[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]strRowSource = strRowSource & strFile & ";"[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]Loop[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]Me.List20.RowSource = Left(strRowSource, Len(strRowSource) - 1)[/COLOR][/FONT]
[FONT=Verdana][COLOR=black]End Sub[/COLOR][/FONT]

in the
Code:
strFile = Dir("C:\MY FOLDER NAME\")
section, how can I modify it so that the subfolder is based on the value of fldA?


i.e.
Code:
strFile = Dir("C:\My Documents\***text in fldA***")
 
Haven't you already started a couple of threads concerning this issue, out of curiosity?
 
strFile = Dir("C:\My Documents\" & me.fldA)

should do the trick
 
The other thread you're referring to is regarding making a folder value based on fldA.value when creating a folder. This is for showing the contents of a directory where the directory value equals fldA.value.
 
I used the code, but got an error stating "Compile Error: Syntax Error"

Code:
strFile = Dir("C:\Documents and Settings\Desktop\" & me.fldA")
 
Ok, I got it right, but now I get an error on the follow section:

Code:
Me.List20.RowSource = Left(strRowSource, Len(strRowSource) - 1)

Can anyone tell me why?
 
did you do a debug.print on

Left(strRowSource, Len(strRowSource) - 1)?

Also, is strRowSource a valid Sql Statement?
 
I'm not sure what you mean by
Also, is strRowSource a valid Sql Statement?

Also, how do you display the results of a debug again?
 
If you perform a Debug.Print strRowSource after you have parsed it it will show the results in the immediate window.

The error will most likely be that you cannot chop of the last character is the string is empty or has no length.

See attach demo of populating a list box with specified files

David
 

Attachments

I'm a novice at this stuff...

Could you give me a step by step?
 
the second attachment seems to be what I;m looking for, but where's the form to see the backend code?
 
Sorry the form has been set to be hidden, you need to go to Tools, Options, General, Show hidden files.

David
 
I'm sorry. You're way ahead of my skill level. I'm just looking for a simple listbox that displays files in a folder that is defined as such = "c:\desktop\" & Me.fldA. Is there something that simple or should I expect the code to be this intricate?
 
Ok, I got it right, but now I get an error on the follow section:

Code:
Me.List20.RowSource = Left(strRowSource, Len(strRowSource) - 1)

Can anyone tell me why?

Just hanging back to this, your probably getting an error because the (rowsource of the) listbox can only contain so many charachters... and you are trying to feed it to many...

To see the form in David's database, try opening attached db
 

Attachments

Is there a way to cut the number of characters so that it will fit the maximum number of characters allowable in the listbox?
 
Ok. I made some edits to the database you provided.. (hope you don't mind). But what do I need to do to remove the TxtExtension and TxtFilter; display the current folder - "c:\desktop\" & Me.fldA -; and to have it automatically display the results of what is in the folder?
 
Ok, I figured most of it out except 2 things

1. How can I change the Browse button into a save button that saves into the "c:\desktop\" & Me.fldA folder?

2. How do I have it automatically display the results of what is in the folder?
 
This demo covers serveral topics, The main one you need to concentrate on is the Function FindFilesInFolder() as trace it backwards.

David
 

Users who are viewing this thread

Back
Top Bottom