Click to See Complete Forum and Search --> : Drive List


Glen Darling
June 22nd, 2000, 02:16 PM
I am trying to obtain a list of drives for searching for the user to select from for certain documents and I am having a little bit of a problem with the drive scan. The code I am just testing out at this point is failing on a removable drive ex drive A: and errors out of the program. The code is as follows:


Sub ShowDriveList()
Dim fs, d, dc, s, n
set fs = CreateObject("Scripting.FileSystemObject")
set dc = fs.Drives
for Each d In dc
s = s & d.DriveLetter & " - "
If d.DriveType = Remote then
n = d.ShareName
else
n = d.VolumeName
End If
s = s & n & vbCrLf
next
MsgBox s
End Sub




Right now when run if I have a disk in drive A: it works fine but if I don't have one it doesn't. Is there a way around this?

Thanks.

John G Duffy
June 22nd, 2000, 02:45 PM
You need to handle the Not ready error yourself using On Error do something
If you want to ignore the not Ready use

"On Error Go To somewhere" to bypass the error. I am returning a real simple example of your Sub with a couple of mods

Sub ShowDriveList()

Dim fs, d, dc, s, n
Set fs = CreateObject("Scripting.FileSystemObject")
Set dc = fs.Drives
On Error GoTo DriveError
For Each d In dc
s = s & d.DriveLetter & " - "
If d.DriveType = Remote Then
n = d.ShareName
Else
n = d.VolumeName
End If
s = s & n & vbCrLf
Next
MsgBox s
Set dc = Nothing
Set fs = Nothing
Exit Sub
DriveError:
n = "Not Ready"
Resume Next
End Sub


John G