Trimming filenames

  • Thread starter Thread starter Sandy
  • Start date Start date
S

Sandy

I collect a path (C:\Documents\Pictures\Parkway.jpg)in a
text box. I would like to create another text box or
label, that would show only the file name (Parkway) If I
have to, I can live with (Parkway.jpg). Please help. I
thought I was good with Access, but I'm still learning.
 
Access 2000 or later? Use InstrRev() to find the last backslash, then Mid()
to get the rest.

Earlier versions: use the trick that Dir() returns just the file name from a
fully qualified name.
 
Allen,
Thanks, so much, for your help. However, I can't seem to
figure out the proper syntax. Can you help?
 
Assuming you've got C:\Documents\Pictures\Parkway.jpg stored in a variable
strFileName, InStrRev(strFileName, "\") will return 22, telling you that the
last slash in the string in in position 22. To get everything after that
position (i.e.: Parkway.jpg), use the Mid function:

Mid(strFilename, InStrRev(strFileName, "\") + 1)

Alternatively, Dir(strFileName) will return Parkway.jpg, but only if the
file actually exists on the computer.
 
Back
Top