UtterAccess HomeUtterAccess Wiki

Welcome Guest ( Log In | Register )

Custom Search
Edit Discussion
> GetFilenameFromPath    
CODE

' Code courtesy of UtterAccess Wiki
' http://www.utteraccess.com/wiki/index.php/Category:FunctionLibrary
'
' You are free to use this code in any application,
' provided this notice is left unchanged.
'
' REV  DATE                          DESCRIPTION
' 1.0  2010-08-10              initial release
' 2.0  2010-09-03              made faster, commented previous version
' 2.1  2010-09-10              reformat, remove previous commented version
'                              changed header
'                              no functional changes made since 2.0
'==============================================================================
' NAME: GetFilenameFromPath
' DESC: Removes directory from a complete filedesignation, returning filename
'       Returns ZLS on input missing "/" or "\"
'       this function requires Access 2000 or a custom InStrRev function.
'==============================================================================
Public Function GetFilenameFromPath(asPath) As String
On Error GoTo Error_Proc
Dim Ret As String
'=========================
 Dim iPos As Integer
'=========================

iPos = InStrRev(asPath, "\")
If iPos > 0 Then
   Ret = Mid$(asPath, iPos + 1)
End If

'=========================
Exit_Proc:
 GetFilenameFromPath = Ret
 Exit Function
Error_Proc:
 MsgBox "Error: " & Trim(Str(Err.Number)) & vbCrLf & _
   "Desc: " & Err.Description & vbCrLf & vbCrLf & _
   "Procedure: GetFilenameFromPath" _
   , vbCritical, "Error!"
 Resume Exit_Proc
 Resume
End Function


Creative Commons License
GetFilenameFromPath by UtterAccess Wiki is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Editing and revision of the content is freely encouraged; for details, see Expected Usage.

Edit Discussion
Custom Search
Thank you for your support!
This page has been accessed 4,207 times.  This page was last modified 08:33, 6 April 2011 by Jack Leach. Contributions by tvanstiphout  Disclaimers