parse data from text field

A

accessuser1308

I currently have a field in a form that contains the exact path to files
stored on my computer (ex. C:\file1\file2\file3\samplefile.doc). The path to
the file is different for most of the files. I have changed some things in
the database and I would like to parse just the file name and extension (ex.
samplefile.doc). I have tried the Mid, Left, Right, and InStr functions but
I have not been able to get the desired data. Any help with code to parse
the data correctly would be appreciated. The names of files are not equal in
length.

Thank you
 
G

Gina Whipp

accessuser1308,

You kinda need a combination... Paste the below into a query...

MyFile:
Right([FieldNameThatContainsFullPath],Len([FieldNameThatContainsFullPath])-InStrRev([FieldNameThatContainsFullPath],"\"))

--
Gina Whipp
2010 Microsoft MVP (Access)

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm
 
S

Stuart McCall

accessuser1308 said:
I currently have a field in a form that contains the exact path to files
stored on my computer (ex. C:\file1\file2\file3\samplefile.doc). The path
to
the file is different for most of the files. I have changed some things
in
the database and I would like to parse just the file name and extension
(ex.
samplefile.doc). I have tried the Mid, Left, Right, and InStr functions
but
I have not been able to get the desired data. Any help with code to parse
the data correctly would be appreciated. The names of files are not equal
in
length.

Thank you

You'll find all you need for slicing & dicing paths here:

http://www.smccall.demon.co.uk/Strings.htm#PathFuncs

FilePart is the function you need immediately.
 
J

John Spencer

If you wanted to confirm that the file actually existed, you could use:
strFileName = DIR([FilePath])
If strFileName is zero-length then the file does not exist at the specified
location.

Otherwise you can use an expression like:
strFileName = Mid([FilePath],InStrRev([FilePath],"\")+1)

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County
 

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

Similar Threads


Top