Referring to file path

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Coolboy55
    New Member
    • Jul 2007
    • 67

    Referring to file path

    I have file paths to pictures in a number of tables, and I'm wondering if there is a way to specify the path as the current directory or a subdirectory of the current directory so that the pictures can be moved with the database and the link will not be lost. Can anyone help?

    Thanks!

    CB55
  • pdebaets
    New Member
    • Mar 2008
    • 16

    #2
    You can use the path from your CurrentDb().nam e to serve as part of the path to your pictures. The function below will return the path from a full path and filename string. Just pass it CurrentDb.Name:

    Code:
    Function xg_GetFolderFromFilename(pstrFilename As String) As String
    Dim Marker As Integer
    Dim strRtn As String
    'Dim intpos As Integer
    Dim i As Integer
    
    On Error GoTo err_section
    Marker = 1
    
    strRtn = ""
    
    For i = Len(pstrFilename) To 1 Step -1
        If Mid(pstrFilename, i, 1) = "\" Then
            Exit For
        End If
    Next i
    
    If i = 1 Then
        If Mid(pstrFilename, i, 1) = "\" Then
            strRtn = "\"
        Else
        End If
    Else
        strRtn = Mid(pstrFilename, 1, i)
    End If
    
    Exit_Section:
        On Error Resume Next
        xg_GetFolderFromFilename = strRtn
        On Error GoTo 0
        Exit Function
    err_section:
        Beep
        MsgBox "Error in xg_GetFolderFromFilename (" & Marker & "): " & Err.Number & " - " & Err.Description
        Err.Clear
        Resume Exit_Section
    
    End Function

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32661

      #3
      If you actually want the current working directory (as opposed to the directory the db is in) then you simply leave out the first "\". Any subfolders of that work in a similar way.

      EG. "MyWord.Doc "; "SubFolder\MyWo rd.Doc"

      Comment

      Working...