Results 1 to 5 of 5

Thread: [RESOLVED] Directory listing

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2006
    Posts
    20

    Resolved [RESOLVED] Directory listing

    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

  2. #2
    Lively Member New2vba's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    95

    Re: Directory listing

    Perhaps Dkenny's post is a good place to start?

    See http://www.vbforums.com/showthread.php?t=395514
    "Those things we must learn to do, we must learn by doing" (or hope somebody else will take pity and help out )

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Feb 2006
    Posts
    20

    Re: Directory listing

    Ok thanks i will check it out

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Feb 2006
    Posts
    20

    Re: Directory listing

    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

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Feb 2006
    Posts
    20

    Re: Directory listing

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width