Results 1 to 6 of 6
  1. #1
    LightKnight is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2020
    Posts
    7

    UNC/ Relative Paths


    My database currently stores documents (contracts) but this is not sustainable as I am going to hit the 2GB limit and I don't want to move to a SQL backend at this point as it removes my ability to make quick and easy changes to the backend (corporate rules). So I am looking at the option to rather store links to the documents. I do however need those links to be UNC and not relative links so that other users can open my documents and me theirs. I have not been able to find a way to convert relative file paths to absolute file paths. It seems to me like it should be reasonably easy or at least well understood but I just can't find a explanation or better still a code snippet. Does anyone have a suggestion that will point me in the right direction?

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    8,279
    run an update query to alter the letter: t:\folder
    to full unc: \\server\folder\folder

    then use this utility to open the file. It will open any file in its app.
    paste this code into a module. (Alt-F11, insert , module)
    Then it will open ANY file via its extension....
    .pdf files will open in acrobat,
    .doc files in word
    etc


    USAGE:
    OpenNativeApp "c:\folder\file.xls"
    'opens in excel
    or
    OpenNativeApp txtBox
    'opens item in field in native app


    Code:
    Option Compare Database
    Option Explicit
    
    
    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
    Private Declare Function GetDesktopWindow Lib "user32" () As Long
    Const SW_SHOWNORMAL = 1
    Const SE_ERR_FNF = 2&
    Const SE_ERR_PNF = 3&
    Const SE_ERR_ACCESSDENIED = 5&
    Const SE_ERR_OOM = 8&
    Const SE_ERR_DLLNOTFOUND = 32&
    Const SE_ERR_SHARE = 26&
    Const SE_ERR_ASSOCINCOMPLETE = 27&
    Const SE_ERR_DDETIMEOUT = 28&
    Const SE_ERR_DDEFAIL = 29&
    Const SE_ERR_DDEBUSY = 30&
    Const SE_ERR_NOASSOC = 31&
    Const ERROR_BAD_FORMAT = 11&
    
    
    Public Sub OpenNativeApp(ByVal psDocName As String)
    Dim r As Long, msg As String
    
    
    r = StartDoc(psDocName)
    If r <= 32 Then
        'There was an error
        Select Case r
            Case SE_ERR_FNF
                msg = "File not found"
            Case SE_ERR_PNF
                msg = "Path not found"
            Case SE_ERR_ACCESSDENIED
                msg = "Access denied"
            Case SE_ERR_OOM
                msg = "Out of memory"
            Case SE_ERR_DLLNOTFOUND
                msg = "DLL not found"
            Case SE_ERR_SHARE
                msg = "A sharing violation occurred"
            Case SE_ERR_ASSOCINCOMPLETE
                msg = "Incomplete or invalid file association"
            Case SE_ERR_DDETIMEOUT
                msg = "DDE Time out"
            Case SE_ERR_DDEFAIL
                msg = "DDE transaction failed"
            Case SE_ERR_DDEBUSY
                msg = "DDE busy"
            Case SE_ERR_NOASSOC
                msg = "No association for file extension"
            Case ERROR_BAD_FORMAT
                msg = "Invalid EXE file or error in EXE image"
            Case Else
                msg = "Unknown error"
        End Select
    '    MsgBox msg
    End If
    End Sub
    
    
    Private Function StartDoc(psDocName As String) As Long
    Dim Scr_hDC As Long
    
    
    Scr_hDC = GetDesktopWindow()
    StartDoc = ShellExecute(Scr_hDC, "Open", psDocName, "", "C:\", SW_SHOWNORMAL)
    End Function

  3. #3
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Posts
    456
    Here's a function I found some time ago.
    Note: Needs a reference to MS Scripting runtime.

    Code:
    Function GetUNC(strMappedDrive As String) As String
     
        Dim objFso As FileSystemObject
        On Error GoTo GetUNC_Error
     
        Set objFso = New FileSystemObject
        Dim strDrive As String
        Dim strShare As String
     
        'Separated the mapped letter from
        'any following sub-folders
        strDrive = objFso.GetDriveName(strMappedDrive)
     
        'find the UNC share name from the mapped letter
        strShare = objFso.Drives(strDrive).ShareName
     
        'The Replace function allows for sub-folders
        'of the mapped drive
        GetUNC = Replace(strMappedDrive, strDrive, strShare)
     
        Set objFso = Nothing    'Destroy the object
     
        On Error GoTo 0
        Exit Function
     
    GetUNC_Error:
     
        MsgBox "Error " & err.Number & " (" & err.Description & ") in procedure GetUNC of Module modAlwaysIncluded"
     
    End Function

  4. #4
    LightKnight is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2020
    Posts
    7
    Thanks for this but it addresses an issue that I haven't got to yet. I see that the wording of my post is misleading so let me explain and see if I get it right. My issue is not that I have lots of links that I need to change. My issue is that if I insert a hyperlink I get a relative link e.g. R:\folder\filename but what I want to do is insert a UNC instead of a relative link. From a user perspective, they should just locate the file via the file dialog box but the database should then insert a UNC link and not a relative link. This seems to be difficult to do much to my surprise.

  5. #5
    LightKnight is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2020
    Posts
    7
    OK, I see the second function posted. After bit of fiddling to work it all out, I have it working. Awesome, thanks for the help!

  6. #6
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Posts
    456

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

Similar Threads

  1. Replies: 8
    Last Post: 05-31-2016, 01:39 PM
  2. How to hide paths of hyperlinks?
    By jobbie in forum Forms
    Replies: 4
    Last Post: 05-06-2015, 09:46 AM
  3. Alternate Form Navigation Paths
    By acannon in forum Forms
    Replies: 4
    Last Post: 04-30-2015, 08:09 AM
  4. Query Critera w/ two Paths
    By Mike4172 in forum Queries
    Replies: 6
    Last Post: 04-10-2013, 08:47 PM
  5. Setting paths different for each form
    By sailinxtc in forum Programming
    Replies: 9
    Last Post: 04-04-2010, 09:03 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 - Senior Forums