Home > Back-end >  How to find current MS Access database path
How to find current MS Access database path

Time:03-29

I have a MS Access application connected to a MS Access database, what I want is to show the path of the database in a textbox. For example, let the database path be D:\New Folder\Database\Test.accdb How can this path be shown in the text box? I tried this code but it doesn't work

Me.Text71 = CurrentDb.Path

CodePudding user response:

If you want to get the path name of the backend database you could use the following code in order to get the name of the backend database.

Put the following code in a general module (Insert/Module)

Public Function getDBname(tblName As String) As String

    Dim db As DAO.Database
    Dim tdf As DAO.TableDef
    Dim con() As String
    Dim i As Long
 
    On Error GoTo EH

    Set db = CurrentDb
    Set tdf = db.TableDefs(tblName)
    con = Split(tdf.Connect, ";")
    For i = 0 To UBound(con)
        If Left(con(i), 9) = "DATABASE=" Then
            getDBname = Mid(con(i), 10)
        End If
    Next i

EH:

End Function

Then you could use

 Me.Text71 = getDBname ("tbl1")

tbl1 has to be the name of a linked table from the backend database you are after.

As mentioned in the comments a frontend could be connected to different backend databases. So, use with care.

  • Related