Results 1 to 10 of 10
  1. #1
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Retrieving folder's path (WinNT4, Word97)

    Could anyone tell me, please, how I can retrieve the true path of a virtual drive?

    In our organisation, each user has a drive T: where the workgroup templates are found, but each department's T: drive is different - as the administrator I see the root for T: and all the department's folders as subfolders of that root - and I need to get the full path for the current user's T: drive.

    This has been driving me batty for about an hour! <img src=/S/hairout.gif border=0 alt=hairout width=31 height=23>
    Beryl M


  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Retrieving folder's path (WinNT4, Word97)

    You need the API function WNetGetConnection for this.

    Declare Function WNetGetConnection Lib "mpr.dll" Alias "WNetGetConnectionA" _
    (ByVal lpszLocalName As String, _
    ByVal lpszRemoteName As String, _
    cbRemoteName As Long) As Long

    Function GetUNCPath(DriveLetter As String) As String
    On Error GoTo Err_Handler
    Dim strLocalName As String
    Dim strRemoteName As String
    Dim lngSize As Long
    strLocalName = DriveLetter
    strRemoteName = Space(255)
    lngSize = Len(strRemoteName)
    If WNetGetConnection(strLocalName, strRemoteName, lngSize) = 0 Then
    GetUNCPath = Left(strRemoteName, lngSize)
    End If
    Exit Function
    Err_Handler:
    MsgBox Err.Description, vbInformation
    End Function

    In your case, GetUNCPath("T:") will return the full UNC path of the T: drive.

  3. #3
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Retrieving folder's path (WinNT4, Word97)

    Thanks, Hans, and it looks great - but when I try to run the code I get a message that says " ... and Declare statements are not allowed as Public members of display modules".

    What am I doing wrong?!
    Beryl M


  4. #4
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Retrieving folder's path (WinNT4, Word97)

    Try replacing Declare Function WNetGetConnection with Private Declare Function WNetGetConnection

    Andrew C

  5. #5
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Retrieving folder's path (WinNT4, Word97)

    Hans, panic over! I just added 'Private' at the front of the Declare statement (since it said it was not allowed to be a 'Public' member) and it's fine!

    Many thanks <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>
    Beryl M


  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Retrieving folder's path (WinNT4, Word97)

    You can either put Private before the Declare statement, or put it in a standard module (I assume it is in the module belonging to a UserForm now). If you opt for the first, the statement would look like

    Private Declare Function WNetGetConnection Lib "mpr.dll" Alias "WNetGetConnectionA" _
    (ByVal lpszLocalName As String, _
    ByVal lpszRemoteName As String, _
    cbRemoteName As Long) As Long

  7. #7
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Retrieving folder's path (WinNT4, Word97)

    Thanks, Andrew - as you can see from the times, I was just typing my note saying I had realised exactly that at the moment you were saying it!

    Many thanks <img src=/S/thankyou.gif border=0 alt=thankyou width=40 height=15>
    Beryl M


  8. #8
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Retrieving folder's path (WinNT4, Word97)

    Actually, it's in 'thisdocument' - is that a module or is it called something else? - but yes, that's exactly what I did. <img src=/S/thumbup.gif border=0 alt=thumbup width=15 height=15>
    Beryl M


  9. #9
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Retrieving folder's path (WinNT4, Word97)

    Hans, going back to the code itself, could you tell me why we have the line about space(255)? The reason I ask is that I need to extract some information from this path, and using Len(strRemoteName) doesn't work - apparently because it has been extended out to 255+ characters long!
    Beryl M


  10. #10
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Retrieving folder's path (WinNT4, Word97)

    Hans, again, don't worry - with a bit of experimenting with Trim, Len, Mid, Left, Right, etc I managed to get it to behave!

    Edited - oops, answered myself instead of Hans!
    Beryl M


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •