Showing a list of documents in an unbound list box

Simple Software Solutions

Without actually looking at your code, you need to find the line that adds the item to the list box first.

Once you have located this - it should look something like

Me.Listbox.AddItem (path and file name)

What you need to do is to split the line into two sections, the file path and the file name. To do this use the InStrRev(String,"\") to locate the last backslash in the string. Everything before this position is the path, and everything after this point is the file name. Store the filename to a string variable and use this string for the AddItem code.

Example:

Full path and file name:
StrString = "C:\Windows\System32\Help.hlp"

X = InStrRev(StrString,"\")

X = 20

StrPath = Left(StrString,X)
StrFile = Mid(StrStirng,X+1)

Coded for brevity


CodeMaster::cool:
 
Thanks for the reply DCrake,

regarding my code, I thought that all you'd need would be the code I placed a link to in my previous post...

I've used that exact code.

When calling it, I used the following command in the strQuotePath_Lost_Focus event:

Code:
me.lstboxQuoteFiles.recordset = ""
Call FindFiles(me.strQuotePath, , True, me.lstboxQuoteFiles)

The first line to clear the list box and the second to call the function and post the results into the quote files list box. I did the same for the project files list box, but used "ProjectFiles" instead of "QuoteFiles" etc...

Simon
 
I've done it :)

There's a section of code in the function called "FillDir()"

'Add the files to the folder.
strFolder = TrailingSlash(strFolder)
strTemp = DIR(strFolder & strFileSpec)
Do While strTemp <> vbNullString
colDirList.Add strFolder & strTemp <---------------------- I removed "strFolder &" from this line
strTemp = DIR
Loop

Also, if there is a comma in any of the file names, the respective file names will not show beyond that point. The extensions will show if the whole of the file name shows though. It now looks like:

quotefiles-fileonly.jpg
 
Simple Software Solutions

I did not know that you could have a comma in a file name! Anyway glad that you have finally got to the bottom of this and everything is working ok.

David:cool:
 
Me too :)

I think I'll have to create a company policy to make people not use commas. It must be acting as a delimiter or something.
 
Simple Software Solutions

Just tried it and low and behold it let me. What you could do is to use the Replace() function to test for commas and if found it substitutes the comma for a underscore for example. The use this new name to rename to old file.All this is done prior to populating the list box or prior to point where you get the error.

Just a suggestion

David
 
This is why I love this forum so much :)

I shall try it and let you know.
 
As for the comma in file names... Why not 'simply' put quotes around the file names??

This should prevent Access from splitting the string up....
colDirList.Add strFolder & strTemp
Would be:
colDirList.Add strFolder & Chr(34) & strTemp & Chr(34)

No need to replace or anything... just Quote it....

Happy coding :)
 
That's a cunning plan. Will try that one maybe instead, it seems less intrusive.


Edit: Yep! that worked mailman, thanks muchly :)
 
Last edited:

Users who are viewing this thread

Back
Top Bottom