Detect the USB drive in drive E:\
Solved
Lenouveauapprenti
Posted messages
306
Registration date
Status
Member
Last intervention
-
Lenouveauapprenti Posted messages 306 Registration date Status Member Last intervention -
Lenouveauapprenti Posted messages 306 Registration date Status Member Last intervention -
Hello
Note: Working environment VB6 with Access 2007
I am looking for a command that notifies me if the E:\ drive is empty (not connected to a USB key)
Thank you for your help
Note: Working environment VB6 with Access 2007
I am looking for a command that notifies me if the E:\ drive is empty (not connected to a USB key)
Thank you for your help
6 answers
-
yg_be Posted messages 23437 Registration date Status Contributor Last intervention Ambassadeur 1 588
-
Hello,
Thank you for the link. Honestly, I can't quite understand how I should use this DriveExists method.
I tried the code below with no result.
Dim oFileSysObj If oFileSysObj.driveexists("E") = False Then MsgBox "Please insert a USB drive" Exit Sub End If
Thank you for any help.-
-
Hello,
Apparently, you haven't read the link from yg_be properly.
Or maybe just skimming through it...
For readers with a removable media, the DriveExists method returns True even if no media is present.
Use the IsReady property of the Drive object to determine if a drive is ready.
Sub test() Dim fs As Object, driv As Object Set fs = CreateObject("Scripting.FileSystemObject") 'creating a FileSystemObject On Error Resume Next Set driv = fs.GetDrive(fs.GetDriveName("E:")) 'creating a Drive object to which we assign drive E: On Error GoTo 0 If Not driv Is Nothing Then 'If drive E: exists If driv.IsReady Then 'if it is ready (media inserted) MsgBox "Cool, there's a USB stick in drive E:" Else 'if it is not ready (no media inserted) MsgBox "Please insert a USB stick" End If Else 'if drive E: does not exist... MsgBox "Drive E: does not exist" End If End Sub
I can't test this code, I don't have a drive E:...
-
-
On the contrary, I read it, only at this object creation function
(CreateObject("Scripting.FileSystemObject")
the application was sending me a message regarding ActiveX
Moreover, to tell you the truth, I did not fully understand it.
I will try your suggestion and I will let you know the result.
Thank you, to you, to yg_be, and everyone. -
Votre code fonctionne à merveille, auquel j'ai ajouté quelques lignes pour mes besoins, mais, j'ai échoué une autre fois.
L'idée une fois la clé USB est détectée, vérifie si le chemin de la BD existe.
Merci de bien vouloir corriger ce que j'ai ajouté.
Dim fs As Object, driv As Object 'première déclaration ajoutée Dim Doss As String Doss = "E:\InstAppSLiquidations\AppSLiquidations\BDLiquidations.mdb" Set fs = CreateObject("Scripting.FileSystemObject") 'création d'un objet FileSystemObject On Error Resume Next Set driv = fs.GetDrive(fs.GetDriveName("E:")) 'création d'un objet Drive auquel on affecte le lecteur E: On Error GoTo 0 If Not driv Is Nothing Then 'Si le lecteur E: existe If driv.IsReady Then 'si il est prêt (média inséré) ' deuxième ajout : Affectation un chemin vers la BD If driv.GetAbsolutePathName("E:\InstAppSLiquidations\AppSLiquidations\BDLiquidations.mdb") = Doss Then 'Verification de l'existence du chemin MsgBox "Chemin trouvé" Call CheminCopies 'Chemin pour copier les enregistrements manquants Exit Sub Else MsgBox "Chemin non trouvé" Exit Sub End If 'MsgBox "Cool, il y a une clé dans le lecteur E:;" Else 'si il n'est pas prêt (pas de média inséré) MsgBox "Veuillez insérer une Clé USB" End If Else 'si le lecteur E: n'existe pas... MsgBox "Le lecteur E: n'existe pas" End If -
Thank you for the link, honestly I couldn't apply what I read due to lack of understanding.
I tried the following without success, yet I attempted it before using the method: driv.GetAbsolutePathName
'Assign a path to the database driv.FolderExists ("E:\InstMezAppSLiquidations\MezAppSLiquidations\BDLiquidations.mdb") If driv.FolderExists = Doss Then 'Check for path existence MsgBox "Path found" Call CheminCopies 'Path to copy missing records Exit Sub Else MsgBox "Path not found" Exit Sub End If 'MsgBox "Cool, there is a key in drive E:" Else 'if it is not ready (no media inserted) MsgBox "Please insert a USB key" End If -
Thank you for everything.
With my sincere gratitude.