For various reasons, I'm stuck in Access 97 and need to get only the path part of a full pathname.
For example, the name
c:\whatever dir\another dir\stuff.mdb
should become
c:\whatever dir\another dir\
This site has some suggestions on how to do it: http://www.ammara.com/access_image_faq/parse_path_filename.html
But they seem rather hideous. There must be a better way, right?
That's about it. There is no magic built-in function...
This seems to work. The above doesn't in Excel 2010.
You can do something simple like:
Left(path, InStrRev(path, "\"))
Example:
Use these codes and enjoy it.
And here you can call function:
I always used the
FileSystemObject
for this sort of thing. Here's a little wrapper function I used. Be sure to reference theMicrosoft Scripting Runtime
.If you're just needing the path of the MDB currently open in the Access UI, I'd suggest writing a function that parses CurrentDB.Name and then stores the result in a Static variable inside the function. Something like this:
This has the advantage that it only loops through the name one time.
Of course, it only works with the file that's open in the user interface.
Another way to write this would be to use the functions provided at the link inside the function above, thus:
This makes retrieving the current path very efficient while utilizing code that can be used for finding the path for any filename/path.