How to get path to database 
Author Message
 How to get path to database

How can I get the path to the database that my VBA code is running in?  I
need to open a file that is in the same Windows 95 directory as the
database, but different target machines may be running the database in
different directories.

Example:  Database is D:\Engineering\Johnson\Projects.mdb
How can I determine the string, "D:\Engineering\Johnson using VBA code
within Projects.mdb?



Thu, 07 Jun 2001 03:00:00 GMT  
 How to get path to database

Quote:
> How can I get the path to the database that my VBA code is running in?  I
> need to open a file that is in the same Windows 95 directory as the
> database, but different target machines may be running the database in
> different directories.

In Access 95/97:

Function DBPath() As String
    Dim strName As String
    strName = CurrentDb.Name
    DBPath = Left$(strName, Len(strName) - Len(Dir(strName)))
End FUnction

This leaves on the trailing backslash. If you don't want that, use

    DBPath = Left$(strName, Len(strName) - Len(Dir(strName)) - 1)

but I'd leave it on. It's easier to use that way.

In Access 2000 (using an MDB file) -- this method is a little more
"obvious", and I'm all for writing "obvious" code:

Function DBPath() As String
    Dim intPos As Integer
    Dim strName As String

    strName = CurrentDb.Name
    intPos = InstrRev(strName, "\")
    If intPos > 0 Then
       DBPath = Left$(strName, intPos)
    End If
End Function

-- Ken
-- Ken



Fri, 08 Jun 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Putting a picture in a report, but getting just the path from database

2. getting desktop path

3. getting reference path errors, having trouble fixing.

4. getting the DB path?

5. Getting DOS 8.3 path from Windows long file name

6. Getting filename out of fully qualified path

7. Getting UNC Network Path Name

8. Getting the path of the Current DB

9. Getting the path of the Current DB

10. Getting the folder path of the current item

11. Use Windows Dialog for getting a path

12. Getting a File's name and Path

 

 
Powered by phpBB® Forum Software