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
Printable View
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
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
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.