Trimming filenames

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.
 
A

Allen Browne

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.
 
S

Sandy

Allen,
Thanks, so much, for your help. However, I can't seem to
figure out the proper syntax. Can you help?
 
D

Douglas J. Steele

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top