PDA

Click to See Complete Forum and Search --> : [RESOLVED] Directory listing


AllanM
Apr 8th, 2006, 06:08 PM
HI i was wondering if their are any in build ways to list the contents of a directory into say a listbox.

I want to store word documents in directories and then list all the documents in that directory.

And have the user be able to click on the list and it load that word document up

If anyone has any reference on this or code examples that would help a lot thanks

New2vba
Apr 9th, 2006, 06:24 AM
Perhaps Dkenny's post is a good place to start?

See http://www.vbforums.com/showthread.php?t=395514

AllanM
Apr 9th, 2006, 06:27 AM
Ok thanks i will check it out

AllanM
Apr 9th, 2006, 08:15 PM
I did a bit more reading and found that what i wanted to do was use a File List box

so i created one and made the code

Public Sub getLetters(z)
Dim Path As String

Path = App.Path 'gets the location of the application
Path = Path & "\" & z ' sets correct directory
File1.Path = Path

End Sub

The Problem i have now is when i try to select a directory which is not there it will error out.

Im not sure how to write a handeler to control this, what i want it to do is if it cant find the directory to create one.

somthing like

If path not found then
Mkdir path 'create directory at the path
File1.Path = Path
else
File1.Path = Path
end if

AllanM
Apr 11th, 2006, 08:58 AM
Public Sub getLetters(z)
Dim path As String

path = App.path ' gets the location of the application
path = path & "\" & z
Label12.Caption = path

On Error GoTo ErrorHandler
File1.path = path 'sets the directoy path
File1.Refresh
ErrorHandler:

Select Case Err
Case 0
' nothing no message needed
Case 70 ' error code permission denied
MsgBox "Could not create directory for patients letters, check your permissions and try again"
Case 76 ' error for path not found
MkDir path ' add directory creation here

Case Else ' reports error code on other errors
MsgBox "The most recent error number is " & Err & _
". Its message text is: " & Error(Err)
End Select

End Sub


Ok seem to have sorted it, my first time with all this stuff, so if any one knows better ways let me know for a future reference please :)