Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2002
    Posts
    14

    Unanswered: Database location path

    I need help getting the path that the current database is at in code.

    I've tried every property in all of the documents in the database container of the current db, but I can't find the location property.

    You can see the location property in the database when you go to File | Database Properties. It's there on the first tab. I realize that this property would be read-only from access, but I would like to get the value of the property for another process.

    Basically, I want to open a document in the same directory that the database resides in. But I want it to work no matter where the database is located, as long as the document is in the same place.

    Any help?? Or maybe there is another way to get this?

    Thanks in advance.

    dk

  2. #2
    Join Date
    Jun 2002
    Location
    Mpls/St.Paul area
    Posts
    303
    Are you looking for this? db.Name


    '********************************************
    Function getDBPath() As String
    ' PURPOSE: this function figures out the path of the current database
    '********************************************
    'DECLARATIONS
    ....Dim db As Database
    ....Dim blnEnd As Boolean
    ....Dim intPosLooking As Integer
    ....Dim intPos As Integer
    ....Dim strPath As String

    'CODE
    ....blnEnd = False 'initialize
    ....Set db = CurrentDb
    ....intPos = 1 'initialize
    ....Do While Not blnEnd 'loop through the path, looking for the last \
    ........intPosLooking = InStr(intPos, db.Name, "\")
    ........If intPosLooking > 0 Then
    ............intPos = intPosLooking + 1
    ........Else
    ............blnEnd = True
    ........End If
    ....Loop
    ....strPath = Left(db.Name, intPos - 1) 'save the pathname
    ....Set db = Nothing
    ....getDBPath = strPath
    End Function
    John
    This is the day the Lord has made, I will rejoice and be glad in it.

  3. #3
    Join Date
    Nov 2002
    Posts
    14
    Yes, thanks John!

    I can't believe I missed the obvious, I was definately going at it the hard way!

  4. #4
    Join Date
    Dec 2002
    Posts
    10

    Arrow

    Originally posted by dkuttler
    Yes, thanks John!

    I can't believe I missed the obvious, I was definately going at it the hard way!
    Hi,
    There is a dir function available which does the req. of getting path:

    Dim sDBPath As String
    Dim sDBFileName As String
    Dim sCurrentDBPath As String 'Final Path to the current DB folder
    sDBPath = CurrentDb.Name
    sDBFileName = Dir(sDBPath)
    sCurrentDBPath = Left(sDBPath, Len(sDBPath) - Len(sDBFileName))

    I hope this will satisfy your requirement!

    Hello123

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •