Results 1 to 3 of 3

Thread: DriveListBox, DirListBox and FileListBox help

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2000
    Location
    Dayton, OH USA
    Posts
    119

    Question

    Can anyone please give me a good example on how to extract a full path using these three objects. I want the user to choose the drive, then the folder, then the file. From this I want to get a path, ie.

    d:\folder\subfolder\database.mdb

  2. #2
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657
    Here's an example to do what you're looking for. Put a DriveListBox, DirListBox, FileListBox, and CommandButton on your form (leaving the default names). Use the following code:
    Code:
    Private Sub Drive1_Change()
        ' when the drive changes, set the directory box path to the new drive
        Dir1.Path = Drive1.Drive
    End Sub
    
    Private Sub Dir1_Change()
        ' when the directory changes, change the file box path to the directory box path
        File1.Path = Dir1.Path
    End Sub
    
    Private Sub Command1_Click()
        ' when the user clicks a filename in the file box,
        ' you can tell what file was selected by using
        ' "File1.List(File1.ListIndex)" 
        Dim strFullFilename As String
        strFullFilename = Dir1.Path & "\" & File1.List(File1.ListIndex)
        MsgBox "You selected " & strFullFilename                
    End Sub
    "It's cold gin time again ..."

    Check out my website here.

  3. #3
    Hyperactive Member
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    455
    Hello VB-Mike & BruceG,

    I am not a wiseacre but sometimes, for example the A: drive is not present. an Error will occur.
    I do think you can better use the next drive event source:

    Private Sub Drive1_Change()
    On Error GoTo DriveError
    ' when the drive changes, set the directory box path to the new drive
    Dir1.Path = Drive1.Drive
    GoTo DriveEnd
    DriveError:
    MsgBox "Drive not accessible!"
    'Drive1.Drive = Dir1.Path
    DriveEnd:
    On Error GoTo 0
    End Sub

    Good luck both.

    Michelle.

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