Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Help   Contact   Merch   Join   Order   Logon   Forums   
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
List of all available drives
John Davy 
         
5 years ago
Hi
I am looking for a way (VBA) to create a list of all available drives on a computer so I can populate a listbox of the Available drives Suggestions?
John
Adam Schwanz  @Reply  
           
5 years ago
What are you looking to do with the drives? I looked around online a little bit and found this, I had to modify it to get it to work properly with access but it may give you some ideas at least.

Private Sub Command0_Click()
    Dim X As Object
    With CreateObject("Scripting.FileSystemObject")
        For Each X In .Drives
            If .FileExists(X.Path & "\Users\User\Downloads\inspections\inspections.accdb") Then
                Set GetDriveLocation = .GetFile(X.Path & "\Users\User\Downloads\inspections\inspections.accdb")
                MsgBox GetDriveLocation
            End If
        Next
    End With
End Sub

It will look for a certain file in all available drives then msgbox the file path on the drives that have the file there.

You could probably modify it further to only return the drive letter, and then use that for what you're trying to do? Just an idea.
Adam Schwanz  @Reply  
           
5 years ago
I was just testing this some more. It's actually really simple

Private Sub Command0_Click()
    Dim X As Object
    With CreateObject("Scripting.FileSystemObject")
        For Each X In .Drives
            MsgBox X
        Next
    End With
End Sub

That will tell you all the drives on the machine.
John Davy OP  @Reply  
         
5 years ago
Hi Adam,
Your code works as designed. Thanks, I am trying to append this list to a table and need your help again. I am getting a syntax error.
           DoCmd.RunSQL "INSERT INTO DrivesT ([DriveLetter]) Values(" & X & ")"  This code goes just before the Next

Can you show me what I am doing wrong?  Thanks  John
Adam Schwanz  @Reply  
           
5 years ago
It's the dreaded double double quote, this works. Might want to wrap in warnings off too so you don't have to keep pushing yes.

DoCmd.SetWarnings False
DoCmd.RunSQL "INSERT INTO DrivesT ([DriveLetter]) Values(""" & X & """)"
DoCmd.SetWarnings True
John Davy OP  @Reply  
         
5 years ago
Hi Adam
So right you are! You are great and I really appreciate all that you did. I am enclosing the completed code whic
created a table of all the drive letters. I have a combo box on a setup form so the user can pick the drive where
a backup is to be stored. Love it  Thanks   John

Private Sub Form_Open(Cancel As Integer)
  DoCmd.SetWarnings False
   DoCmd.RunSQL "DELETE DrivesT.* FROM DrivesT;"
   DoCmd.SetWarnings True

    Dim X As Object
    With CreateObject("Scripting.FileSystemObject")
        For Each X In .Drives
          'MsgBox X
          DoCmd.SetWarnings False
          DoCmd.RunSQL "INSERT INTO DrivesT ([DriveLetter]) Values(""" & X & """)"
          DoCmd.SetWarnings True
        Next
    End With
End Sub

Adam Schwanz  @Reply  
           
5 years ago
Looks good, glad it works. This was something I didn't know you could do either until I played around with it so I learned something new too :).
Scott Axton  @Reply  
      
5 years ago
Good job Adam  I learned too.  Yet another reason I love this community.
Richard Rost  @Reply  
          
5 years ago
Good... now I don't have to cover this in D32. LOL

Seriously though... I've got all that coming up with FileSystemObject... drives on the PC, files in a folder, you name it.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 8/24/2026 9:26:40 AM. PLT: 0s