This will do it. You could change it just to accept either a listbox or combobox, but I made it do either.
VB Code:
Public Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal cchBuffer As Long, ByVal lpzBuffer As String) As Long Public Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal lpzDrive As String) As Long Public Const DRIVE_CDROM As Long = 5 Public Sub AddCDDrives(ByRef ctlListOrCombo As Control) Dim strBuffer As String Dim lngLength As Long Dim astrDrives As Variant Dim i As Long If (TypeOf ctlListOrCombo Is ComboBox) Or (TypeOf ctlListOrCombo Is ListBox) Then 'make a buffer strBuffer = Space$(128) 'get the drive letters lngLength = GetLogicalDriveStrings(Len(strBuffer), strBuffer) 'trim off the last null char strBuffer = Left$(strBuffer, lngLength - 1) 'break the return into separate drives astrDrives = Split(strBuffer, vbNullChar) ctlListOrCombo.Clear 'go through each drive to see if it's a cdrom, and add it if so For i = 0 To UBound(astrDrives) If GetDriveType(astrDrives(i)) = DRIVE_CDROM Then ctlListOrCombo.AddItem astrDrives(i) Next i End If End Sub 'usage AddCDDrives drivelistbox 'or AddCDDrives drivecombobox





Reply With Quote