Article ID: 182306
Article Last Modified on 1/22/2007
Function RetrievePathFile(Optional vComponent As Variant)
' This function takes an optional argument that specifies
' whether you want to return the directory portion of
' the path or the file portion of the path.
' Usage: If you want to return only the name of the file
' without the path, use the syntax:
' RetrievePathFile("FName")
' If you supply a different argument or no argument at all
' the function returns only the folder in which the file is
' located.
Dim strCurDBName As String
Dim i As Integer ' loop counter.
strCurDBName = CurrentDb.Name
' Loop backward through string to find last "\"
For i = Len(strCurDBName) To 1 Step -1
If Mid(strCurDBName, i, 1) = "\" Then
If IsMissing(vComponent) Then
RetrievePathFile = Mid(strCurDBName, 1, i - 1)
ElseIf vComponent = "FName" Then
RetrievePathFile = Mid(strCurDBName, i + 1)
Else
RetrievePathFile = Mid(strCurDBName, 1, i - 1)
End If
Exit For
End If
Next i
End Function
?RetrievePathFile("FName")
The function returns the name of the current database without the
complete path.
?RetrievePathFile()The function returns the path of the folder in which the current database is located.
163435 VBA: Programming Resources for Visual Basic for Applications
Additional query words: kbmacro vba
Keywords: kbhowto kbprogramming KB182306