Access MVP Graham Mandeno wrote the following code which will help you
locate the CD drive:
------------ code start ---------------
Option Explicit
Option Compare Text
Option Base 0
' © Graham Mandeno, Alpha Solutions, Auckland, New Zealand
' This code may be used and distributed freely on the condition
' that the above credit is included unchanged.
Private Declare Function GetLogicalDriveStrings _
Lib "kernel32" Alias "GetLogicalDriveStringsA" _
(ByVal nBufferLength As Long, _
ByVal lpBuffer As String) _
As Long
Private Declare Function GetDriveType _
Lib "kernel32" Alias "GetDriveTypeA" _
(ByVal nDrive As String) _
As Long
Private Declare Function GetVolumeInformation _
Lib "kernel32" Alias "GetVolumeInformationA" _
(ByVal lpRootPathName As String, _
ByVal lpVolumeNameBuffer As String, _
ByVal nVolumeNameSize As Long, _
lpVolumeSerialNumber As Long, _
lpMaximumComponentLength As Long, _
lpFileSystemFlags As Long, _
ByVal lpFileSystemNameBuffer As String, _
ByVal nFileSystemNameSize As Long) _
As Long
Private Const DRIVE_UNKNOWN = 0
Private Const DRIVE_NOROOT = 1
Private Const DRIVE_REMOVABLE = 2
Private Const DRIVE_FIXED = 3
Private Const DRIVE_REMOTE = 4
Private Const DRIVE_CDROM = 5
Private Const DRIVE_RAMDISK = 6
Public Function CDRomPath(sVolumeLabel As String) As String
' Returns the path ("X:\") of the CD-ROM drive containing the given CD
' If not found, returns a null string
Static aCDPaths As Variant, sCDPath As String
Dim i As Integer
If IsEmpty(aCDPaths) Then aCDPaths = GetAvailableCDs
If Not IsNull(aCDPaths) Then
For i = 0 To UBound(aCDPaths)
sCDPath = aCDPaths(i)
If GetVolumeLabel(sCDPath) = sVolumeLabel Then
CDRomPath = sCDPath
Exit For
End If
Next
End If
End Function
Public Function GetAvailableCDs() As Variant
' Returns a zero-based string array of available CD-ROM drives
' Each element is in the form "X:\"
Dim aDrives() As String, sAllDrives As String, sOneDrive As String
Dim iDrives As Integer, iAllDrives As Integer, i As Integer
sAllDrives = String(26 * 4 + 1, 0)
iAllDrives = GetLogicalDriveStrings(Len(sAllDrives), sAllDrives) \ 4
For i = 0 To iAllDrives - 1
sOneDrive = Mid(sAllDrives, i * 4 + 1, 3)
If GetDriveType(sOneDrive) = DRIVE_CDROM Then
ReDim Preserve aDrives(iDrives)
aDrives(iDrives) = sOneDrive
iDrives = iDrives + 1
End If
Next
If iDrives Then
GetAvailableCDs = aDrives
Else
GetAvailableCDs = Null
End If
End Function
Public Function GetVolumeLabel(sDrivePath As String) As String
' Return the volume label of the media in drive "X:\"
Dim sLabel As String, iLen As Integer
sLabel = String$(14, 0)
If GetVolumeInformation(sDrivePath, sLabel, Len (sLabel), _
0, 0, 0, vbNullString, 0) > 0 Then
iLen = InStr(sLabel, vbNullChar) - 1
If iLen Then
GetVolumeLabel = Left$(sLabel, iLen)
Else
GetVolumeLabel = "(no label)"
End If
End If
End Function
---------------- code end ----------------------
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access