Avatar of shambalad
shambalad
Flag for United States of America asked on

Retrieve Back-End Database path

I am looking for an easy way to retrieve the path to the Back-End database.
Thanks,
Todd
Microsoft Access

Avatar of undefined
Last Comment
shambalad

8/22/2022 - Mon
shambalad

ASKER
Probably should add that I will be using a default linked table named 'tblOpenLink'.
Rey Obrero (Capricorn1)



      Dim strTest As String, db As DAO.Database
      Dim td As DAO.TableDef
      Set db = CurrentDb
      For Each td In db.TableDefs
         If Len(td.Connect) > 0 Then   ' Is a linked table.
         'get Backend path

            sBEpath = Mid(td.Connect, InStr(td.Connect, "=") + 1)
            msgbox  sBEpath
            exit for
         end if
     next
RgGray3

You can query the MSysObjects table for your tablename in the ForeigenName Field and retrieve the Database field which will have the full path name of the back end mdb
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
shambalad

ASKER
Capicorn1 -
I was trying a variation on your suggestion, but getting an error (see snippet).
Public Sub GetBackEndPath()
   Dim strPath As String
   Dim tdf As TableDef
   Set tdf = CurrentDb.TableDefs("tblOpenLink")
   
   ' Runtime error 3420 'Object invalid or
   ' no long set on following instruction
   strPath = Mid(tdf.Connect, InStr(tdf.Connect, "=") + 1)
   
   Debug.Print strPath
End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Rey Obrero (Capricorn1)

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
shambalad

ASKER
That works.
Just out of curiousity. Why do I have to go through the additional step of defining and assigning a database object?
Rey Obrero (Capricorn1)

from the VBA window > Help
type currentdb
open currentdb method for full explanation
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
shambalad

ASKER
Thanks -
In thinking about this last question, I figured it was time to pull out my 'Developer's Handbook' by Ken Getz et al.
At the risk of being too simplistic:
For most objects referenced using 'Currentdb', Access essentially creates an explicit reference to the current database that is only valid for that particular line of code. Once that line has executed, Access 'closes' the reference. Hence subsequent instructions that refer to the object will fail. A notable exeception to this rule is the 'Recordset' object. Here Access maintains the reference to the current database.
shambalad

ASKER
RgGray3 - I just wanted to acknowledge that your suggestion works perfectly fine, too. Capricorn1 was there first, though, and I will be using his method.
Thanks,
Todd