Results 1 to 11 of 11
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    2,097

    reference "Google Drive" in code

    Given the drive letter of the current environments "Google Drive" unknown to code, is there a way to reference the drive with just it's common name. E.g., "%Google Drive%\My Drive\MyFolder\MyFile.pdf" Or, is there a function that will give code the drive letter?

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    2,097
    I found one solution following the URL's you gave: (Daniel Pineault's comments suggests the code is copyrighted, so I'm not sure I can use it even for private use?)

    Code:
    Option Compare Database
    Option Explicit
    
    
    Private Sub DL()
    MsgBox WMI_GetDriveByName("Google Drive")
    End Sub
    
    
    
    
    Public Function WMI_GetDriveByName(ByVal sDriveName As String) As String
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    '  Procedure : WMI_GetDriveByName
    '  Author    : Daniel Pineault, CARDA Consultants Inc.
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
        On Error GoTo Error_Handler
        #Const WMI_EarlyBind = False   'True => Early Binding / False => Late Binding
        #If WMI_EarlyBind = True Then
            Dim oWMI              As WbemScripting.SWbemServices
            Dim oCols             As WbemScripting.SWbemObjectSet
            Dim oCol              As WbemScripting.SWbemObject
        #Else
            Dim oWMI              As Object
            Dim oCols             As Object
            Dim oCol              As Object
            Const wbemFlagReturnImmediately = 16    '(&H10)
            Const wbemFlagForwardOnly = 32          '(&H20)
        #End If
        Dim sWMIQuery             As String         'WMI Query
     
        Set oWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
        sWMIQuery = "SELECT DeviceID FROM Win32_LogicalDisk WHERE VolumeName='" & sDriveName & "'"
        Set oCols = oWMI.ExecQuery(sWMIQuery, , wbemFlagReturnImmediately Or wbemFlagForwardOnly)
        For Each oCol In oCols
            WMI_GetDriveByName = oCol.DeviceID
            Exit For
        Next
     
    Error_Handler_Exit:
        On Error Resume Next
        Set oCol = Nothing
        Set oCols = Nothing
        Set oWMI = Nothing
        Exit Function
     
    Error_Handler:
        MsgBox "The following error has occurred" & vbCrLf & vbCrLf & _
               "Error Number: " & Err.Number & vbCrLf & _
               "Error Source: WMI_GetDriveByName" & vbCrLf & _
               "Error Description: " & Err.Description & _
               Switch(Erl = 0, "", Erl <> 0, vbCrLf & "Line No: " & Erl) & _
                vbOKOnly + vbCritical, "An Error has Occurred!"
        Resume Error_Handler_Exit
    End Function

  4. #4
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,879
    I think you need an Api from google to access Google Drive. The name may be misleading as it's not really a drive on your machine.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Quote Originally Posted by GraeagleBill View Post
    I found one solution following the URL's you gave: (Daniel Pineault's comments suggests the code is copyrighted, so I'm not sure I can use it even for private use?)

    Code:
    Option Compare Database
    Option Explicit
    
    
    Private Sub DL()
    MsgBox WMI_GetDriveByName("Google Drive")
    End Sub
    
    
    
    
    Public Function WMI_GetDriveByName(ByVal sDriveName As String) As String
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    '  Procedure : WMI_GetDriveByName
    '  Author    : Daniel Pineault, CARDA Consultants Inc.
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
        On Error GoTo Error_Handler
        #Const WMI_EarlyBind = False   'True => Early Binding / False => Late Binding
        #If WMI_EarlyBind = True Then
            Dim oWMI              As WbemScripting.SWbemServices
            Dim oCols             As WbemScripting.SWbemObjectSet
            Dim oCol              As WbemScripting.SWbemObject
        #Else
            Dim oWMI              As Object
            Dim oCols             As Object
            Dim oCol              As Object
            Const wbemFlagReturnImmediately = 16    '(&H10)
            Const wbemFlagForwardOnly = 32          '(&H20)
        #End If
        Dim sWMIQuery             As String         'WMI Query
     
        Set oWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
        sWMIQuery = "SELECT DeviceID FROM Win32_LogicalDisk WHERE VolumeName='" & sDriveName & "'"
        Set oCols = oWMI.ExecQuery(sWMIQuery, , wbemFlagReturnImmediately Or wbemFlagForwardOnly)
        For Each oCol In oCols
            WMI_GetDriveByName = oCol.DeviceID
            Exit For
        Next
     
    Error_Handler_Exit:
        On Error Resume Next
        Set oCol = Nothing
        Set oCols = Nothing
        Set oWMI = Nothing
        Exit Function
     
    Error_Handler:
        MsgBox "The following error has occurred" & vbCrLf & vbCrLf & _
               "Error Number: " & Err.Number & vbCrLf & _
               "Error Source: WMI_GetDriveByName" & vbCrLf & _
               "Error Description: " & Err.Description & _
               Switch(Erl = 0, "", Erl <> 0, vbCrLf & "Line No: " & Erl) & _
                vbOKOnly + vbCritical, "An Error has Occurred!"
        Resume Error_Handler_Exit
    End Function
    Well I used code from the first link. I did tidy it somewhat for it's Dims.
    Code:
    C - Windows
    D - WD Scorpio
    E - Google Drive
    F - DATA
    G - DATA
    J - \\PAULS\JAG Property
    L - \\dlink323\Volume_1
    M - \\dlink323\Volume_1\Music\Music_Collection
    Y - \\DLINK323A\Volume_1
    Z - \\Dlink323\usb250
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #6
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    2,097
    For my specific purpose:
    Code:
    Function GetDriveLetter(VolName As String) As String
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    '  This drive letter find function only works with fixed volumes. A zero length
    '  string is returned if the specified volume is not found among the collection.
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    Const intFixed As Integer = 2
    Dim fs, d, dc
    
    
    GetDriveLetter = ""
    
    
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set dc = fs.Drives
    
    
        For Each d In dc
            If d.drivetype = intFixed Then
                If d.VolumeName = VolName Then GetDriveLetter = d.driveletter
            End If
        Next
    
    
    End Function

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    I see you did not tidy up the Dims.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  8. #8
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    2,097
    Once one downloads the Google Drive App, it will then appear along with all the other drives:
    Click image for larger version. 

Name:	000.jpg 
Views:	23 
Size:	21.3 KB 
ID:	51883

  9. #9
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    2,097
    My sense is that the Dims could use some additional qualifications beyond simply being objects?

    Code:
    Function GetDriveLetter(VolName As String) As String
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    '  This drive letter find function only works with fixed volumes. A zero length
    '  string is returned if the specified volume is not found among the collection.
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    Const intFixed As Integer = 2
    Dim fs As Object
    Dim d As Object
    Dim dc As Object
    
    
    GetDriveLetter = ""
    
    
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set dc = fs.Drives
    
    
        For Each d In dc
            If d.drivetype = intFixed Then
                If d.VolumeName = VolName Then GetDriveLetter = d.driveletter
            End If
        Next
    
    
    End Function

  10. #10
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    FWIW both my DATA volumes were USB sticks that were not present.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  11. #11
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Daniel's code is fairly standard. Anyone can use it.
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 11-14-2019, 11:30 AM
  2. Replies: 2
    Last Post: 12-23-2015, 09:32 PM
  3. Replies: 2
    Last Post: 10-18-2015, 01:17 AM
  4. Replies: 4
    Last Post: 07-12-2014, 02:02 PM
  5. Replies: 17
    Last Post: 06-04-2012, 05:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums