Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Check for USB Drive
William Farrar 
    
2 years ago
Has anyone developed VBA code checking for an USB drive (for backup media)  An added benefit would be checking the volume label and/or if a directory exists.
Jeffrey Kraft  @Reply  
      
2 years ago
I cheated and went to ChatGPT.  I just asked... OK begged is it possible to check for the existence of a USB drive.

Sub CheckUSBDrive()
    Dim fso As Object
    Dim drive As Object
    Dim driveLetter As String
    Dim driveType As String
    
    Set fso = CreateObject("Scripting.FileSystemObject")
    
    ' Define the drive letter for the USB drive you want to check
    driveLetter = "D:"
    
    If fso.DriveExists(driveLetter) Then
        Set drive = fso.GetDrive(driveLetter)
        Select Case drive.DriveType
            Case 1
                driveType = "Removable drive"
            Case 2
                driveType = "Fixed drive"
            Case 3
                driveType = "Network drive"
            Case 4
                driveType = "CD-ROM drive"
            Case 5
                driveType = "RAM disk"
            Case Else
                driveType = "Unknown drive type"
        End Select
        MsgBox "USB Drive found: " & vbCrLf & _
               "Drive Letter: " & driveLetter & vbCrLf & _
               "Drive Type: " & driveType
    Else
        MsgBox "USB Drive not found!"
    End If
    
    Set fso = Nothing
    Set drive = Nothing
End Sub

I could see a use of it especially in my case my portable backup drive or something like that.
William Farrar OP  @Reply  
    
2 years ago
Thank you very much...  I planning on modifying it into a Public Sub in my Module in my Design Template for all New DBs.  A;so,  passing a specific "network" drive letter for the database development backups running every five to ten minutes automatically.
Kevin Yip  @Reply  
     
2 years ago
The method above will recognize USB drives as "fixed drives," not removable drives.  "Removable drives" is a an old lingo that means floppy drives, which you can insert disks into or remove them from -- that is the meaning of "removable" here.

Microsoft's documentation also says "hard drives that are removable" (i.e. USB drives) are also considered "fixed drives:"

     https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/drivetype-constants

You can still detect the presence of an USB drive if you already know its driver letter, which in most cases you do.
Jeffrey Kraft  @Reply  
      
2 years ago
When I first saw the code I was thinking great... but ChatGPT you are assuming the driver letters are never going to change.  For example I have a USB portable CD/DVD read/write drive.  HP and everybody else ditched those a few years ago and that's what I'm stuck with.  My portable WD backup drive... also USB - granted neither is removed.  Or the 3 flash drives.  But I figured what the heck.... get the party started and maybe somebody else with more functioning gray matter when I posted that can handle 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: 5/6/2026 5:19:38 PM. PLT: 1s