Get File Path

G

Guest

Hi there,

I have a quick question for you. I have been able to successfully get the
file path name using the code in the following link below and put the path
name into an existing table:

http://www.mvps.org/access/api/api0001.htm

My question for you is this. Is it possible for this to extract the full
path without the file name attached to it??

C:\MyDocuments\MyFolder\

instead of

C:\MyDocuments\MyFolder\filename.jpg

Or, once I have the full path name, is there an easy way to strip off the
file name and store that in a variable?

If someone could help me out with this, it would be greatly appreciated!!

Thanks so much!
 
D

Douglas J. Steele

Assuming the file exists, and the full path is stored in a variable
strFullPath, the following will return only the folder:

Left$(strFullPath, Len(strFullPath) - Len(Dir$(strFullPath)))

If the file doesn't exist (because you used the dialog to invoke File Save,
not File Open), you can use InStrRev to determine where the last slash
appears in the name, and use the Left$ function to return only the folder:

Left$(strFullPath, InStrRev(strFullPath, "\") - 1)
 
G

Guest

Thanks so much Douglas!

I was toying with that function but just couldn't get it to work correclty.
You are the man! :)
 
B

Brendan Reynolds

The Dir() function is one of the functions that is blocked in queries and
expressions when JET 4 sandbox mode is enabled. See the following KB article
for details ...

http://support.microsoft.com/default.aspx?scid=kb;en-us;294698&Product=acc

While these functions are blocked in queries and expressions when sandbox
mode is enabled, they can still be used in VBA, and your queries and
expressions can use them indirectly by calling custom VBA functions that
call the blocked functions. The following KB article has examples ...

http://office.microsoft.com/en-us/assistance/HP010447361033.aspx
 

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