Option Compare Database

' ** Access Toolbox Module **
' on 2017-02-28,
' @author: Olivier Massot
' V 1.0

' Store and manage external paths

' Needs the 'zt_paths' table

Public Function get_path(ByVal pathname As String, Optional mode As String = "*") As String
    On Error GoTo err
 
    get_path = DFirst("path", "zt_paths", "[pathname]='" & pathname & "' AND [mode] like '" & mode & "'")

fin:
    Exit Function
err:
    If err.number = 94 Then
        MsgBox "Le lien vers '" & nom & "' (mode '" & mode & "') n'existe pas dans ztbl_liens", vbCritical
    Else
        MsgBox "Impossible de trouver le lien '" & nom & "' (mode '" & mode & "'):" & vbNewLine & err.Description, vbCritical
    End If
End Function

Public Sub set_path(ByVal pathname As String, ByVal path As String, Optional mode As String = "*")
    On Error GoTo err
    
    If DCount("path", "zt_paths", "[pathname]='" & pathname & "' AND [mode] like '" & mode & "'") > 0 Then
       sql = "UPDATE zt_paths SET zt_paths.path = '" & path & "'" & _
             "WHERE ((zt_paths.pathname='" & pathname & "') AND (zt_paths.mode Like '" & mode & "'));"
    Else
       sql = "INSERT INTO zt_paths ( pathname, mode, path ) " & _
             "SELECT '" & pathname & "' AS Expr1, '" & mode & "' AS Expr2, '" & path & "' AS Expr3;"
    End If
    
    CurrentDb.execute sql
    
fin:
    Exit Sub
err:
    MsgBox "Erreur lors de la mise à jour du lien '" & pathname & "' (mode '" & mode & "'):" & vbNewLine & err.Description, vbCritical
End Sub