Path of Backend database in a FE/BE scenario
-
- 5StarLounger
- Posts: 1148
- Joined: 08 Feb 2010, 21:27
Path of Backend database in a FE/BE scenario
How do i get the path of the backend database when i am in the frontend?
-
- 2StarLounger
- Posts: 112
- Joined: 25 Jan 2010, 20:19
Re: Path of Backedn database in a FE/BE scenario
If you know the name of a table in the back end:
Code: Select all
Dim sTblDef As String
sTblDef = CurrentDb.TableDefs("test").Properties(4)
MsgBox Mid(sTblDef, InStr(sTblDef, "=") + 1)
-
- 3StarLounger
- Posts: 287
- Joined: 09 Mar 2010, 23:16
- Location: Canberra Australia
Re: Path of Backedn database in a FE/BE scenario
That is quicker than the method I have usually used, but it returns the wrong result if there is a password on the backend.
In that case there are 2 = signs in the string.
I think this works in either case:
MsgBox Mid(sTblDef, InStrRev(sTblDef, "=") + 1)
In that case there are 2 = signs in the string.
I think this works in either case:
MsgBox Mid(sTblDef, InStrRev(sTblDef, "=") + 1)
Regards
John
John
-
- 3StarLounger
- Posts: 331
- Joined: 11 Feb 2010, 03:55
- Location: Land O Lakes, FL
Re: Path of Backedn database in a FE/BE scenario
Or you can try the following (again, you must know the name of a linked table)Pat wrote:How do i get the path of the backend database when i am in the frontend?
strBE = currentdb.tabledefs("sometable").connect
Mark Liquorman
Land O Lakes, FL
see my website http://www.liquorman.net for Access Tips and Tricks, and for my Liquorman Utilities.
Land O Lakes, FL
see my website http://www.liquorman.net for Access Tips and Tricks, and for my Liquorman Utilities.
-
- 5StarLounger
- Posts: 1148
- Joined: 08 Feb 2010, 21:27
Re: Path of Backedn database in a FE/BE scenario
Thanks Mark, yet another way to find it.
-
- 3StarLounger
- Posts: 287
- Joined: 09 Mar 2010, 23:16
- Location: Canberra Australia
Re: Path of Backedn database in a FE/BE scenario
I used to use this function , which does not require a 'seed' table name, but it is quite slow to run, and I used it quite a bit. So I would store the result in a front end table, and normally retrieve it from there.
The loop returns all the queries, and the system tables before getting to the real tables, so you need a way of recognising a real table. In my case I look for the name starting with "tbl".
This requires a Reference to Microsoft ADO EXt for DDL and Security.
The loop returns all the queries, and the system tables before getting to the real tables, so you need a way of recognising a real table. In my case I look for the name starting with "tbl".
This requires a Reference to Microsoft ADO EXt for DDL and Security.
Code: Select all
Public fun ction fnGetBackEndDataFile
Dim cat As ADOX.Catalog
Dim tdftable As ADOX.Table
Dim strdbName As String
Dim sql As String
On Error GoTo fnGetBackendDataFile_Error
Set cat = New ADOX.Catalog
Dim intI As Integer
Dim blfound As Boolean
intI = 1
blfound = False
cat.ActiveConnection = CurrentProject.Connection
On Error Resume Next
Do Until (blfound = True) Or (intI = 100)
Set tdftable = cat.Tables(intI)
' Debug.Print intI, tdftable.Name
If tdftable.Type = "LINK" And Left(tdftable.Name, 3) = "tbl" Then
blfound = True
End If
intI = intI + 1
Loop
' MsgBox (tdftable.Name)
If intI < 100 Then
strdbName = tdftable.Properties("Jet OLEDB:Link Datasource")
Else
' tables are not linked
strdbName = CurrentProject.FullName
End If
' MsgBox (strDBName)
If Len(strdbName) > 0 Then
fnGetBackendDataFile = strdbName
' keep this so we can get it again quickly next time
sql = "Update tbldatapath set tbldatapath.datapath = " & Chr(34) & strdbName & Chr(34) & " where (tbldatapath.[key]=1)"
CurrentDb.Execute sql, dbFailOnError
Else
fnGetBackendDataFile = "not found"
End If
Set tdftable = Nothing
Set cat = Nothing
Exit_fnGetBackendDataFile:
Exit Function
fnGetBackendDataFile_Error:
If Err.Number = 0 Then
Resume Next
Else
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure fnGetBackendDataFile of Module Global Code", , "Error in procedure fnGetBackendDataFile"
Resume Exit_fnGetBackendDataFile
End If
End Function
Regards
John
John
-
- 5StarLounger
- Posts: 1148
- Joined: 08 Feb 2010, 21:27
Re: Path of Backend database in a FE/BE scenario
Wow, all these possibilities, thank you guys.
-
- NewLounger
- Posts: 4
- Joined: 06 Mar 2011, 22:30
- Status: Microsoft MVP
Re: Path of Backend database in a FE/BE scenario
Hi Pat,
You can also get the linked paths using a SQL Statement (query)--no VBA code required. While the SQL involves the msysObjects table, and this is undocumented by Microsoft, the chances of this breaking in a future release are very remote. Here are two variations:
To reveal all linked paths:
SELECT Left(Database,255) AS [Linked Databases],
Count(MsysObjects.Database) AS [Number of Tables]
FROM MsysObjects
WHERE (MsysObjects.Type)<>9
GROUP BY Left(Database,255)
HAVING Left(Database,255) Is Not Null;
If you want to see each table name, use this instead:
SELECT Left(Database,255) AS [Linked Databases], Name, ForeignName
FROM MsysObjects
WHERE (((MsysObjects.Type)<>9))
GROUP BY Left(Database,255), Name, ForeignName
HAVING (((Left([Database],255)) Is Not Null))
ORDER BY Name, ForeignName;
Notes:
1. Make sure to compact the database first, to avoid revealing table links that have already been deleted.
2. Grouping on the first 255 characters is required for Access 97, but not later versions, since [Database] is a memo data type. (Contributed by Doug Steele).
3. The criteria, WHERE (MsysObjects.Type)<>9, is used to filter out any table constraints created with ADO. (Contributed by Dirk Goldgar).
Tom Wickerath
Microsoft Access MVP
2006 - 2011
You can also get the linked paths using a SQL Statement (query)--no VBA code required. While the SQL involves the msysObjects table, and this is undocumented by Microsoft, the chances of this breaking in a future release are very remote. Here are two variations:
To reveal all linked paths:
SELECT Left(Database,255) AS [Linked Databases],
Count(MsysObjects.Database) AS [Number of Tables]
FROM MsysObjects
WHERE (MsysObjects.Type)<>9
GROUP BY Left(Database,255)
HAVING Left(Database,255) Is Not Null;
If you want to see each table name, use this instead:
SELECT Left(Database,255) AS [Linked Databases], Name, ForeignName
FROM MsysObjects
WHERE (((MsysObjects.Type)<>9))
GROUP BY Left(Database,255), Name, ForeignName
HAVING (((Left([Database],255)) Is Not Null))
ORDER BY Name, ForeignName;
Notes:
1. Make sure to compact the database first, to avoid revealing table links that have already been deleted.
2. Grouping on the first 255 characters is required for Access 97, but not later versions, since [Database] is a memo data type. (Contributed by Doug Steele).
3. The criteria, WHERE (MsysObjects.Type)<>9, is used to filter out any table constraints created with ADO. (Contributed by Dirk Goldgar).
Tom Wickerath
Microsoft Access MVP
2006 - 2011
-
- 5StarLounger
- Posts: 1148
- Joined: 08 Feb 2010, 21:27
Re: Path of Backend database in a FE/BE scenario
Thanks Tom, all good info, i will keep that in my bag of tricks.
I have used that table in the past.
It helps when you know what those codings (eg Type<>9) mean.
I have used that table in the past.
It helps when you know what those codings (eg Type<>9) mean.
-
- Administrator
- Posts: 78620
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Path of Backend database in a FE/BE scenario
Hi Tom,
Welcome to Eileen's Lounge! Nice to see you here. I hope you'll enjoy it.
Thanks for your first contribution.
Welcome to Eileen's Lounge! Nice to see you here. I hope you'll enjoy it.
Thanks for your first contribution.
Best wishes,
Hans
Hans