• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 400
  • Last Modified:

find in vba a position from a specific character in a access filed

hi

i have a field that stored files location like this: c:\users\user\sample.

and i want that access will cut the whole file location and leave only the file name ,like the file name "sample" so i need that access will get start search from the last character by the right side and to find if there is a Backslash
and if not to go to the next character from the right side and so on and when it's will find the first backslash to give me the position.

thanks a lot
0
bill201
Asked:
bill201
1 Solution
 
Kelvin SparksCommented:
The functions below will assist you.

Please note that I sourced these from

http://www.vbaexpress.com/kb/getarticle.php?kb_id=767

Kelvin
Option Explicit 
 
 'The following function returns the filename without the extension from the file's full path:
Function FileNameNoExt(strPath As String) As String 
    Dim strTemp As String 
    strTemp = Mid$(strPath, InStrRev(strPath, "\") + 1) 
    FileNameNoExt = Left$(strTemp, InStrRev(strTemp, ".") - 1) 
End Function 
 
 'The following function returns the filename with the extension from the file's full path:
Function FileNameWithExt(strPath As String) As String 
    FileNameWithExt = Mid$(strPath, InStrRev(strPath, "\") + 1) 
End Function 
 
 'the following function will get the path only (i.e. the folder) from the file's ful path:
Function FilePath(strPath As String) As String 
    FilePath = Left$(strPath, InStrRev(strPath, "\")) 
End Function

Open in new window

0
 
bill201Author Commented:
Thanks a lot
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now