Access - DB file path ?
#1
Ok - i want to know the path to where the currentdb sits - so i can import a file in that directory (rather than hard code it as it may move around on our network).
Ive used
application.CurrentDb.Name
But this returns the silly 8bit file extension
"C:\TODAYS~1\StockExport.mdb"
If i then string out the StockExport.mdb bit - i thought i'd cracked it... but it then doesnt like the TODAYS~1
Any other way of finding the app path?
Jza
Ive used
application.CurrentDb.Name
But this returns the silly 8bit file extension
"C:\TODAYS~1\StockExport.mdb"
If i then string out the StockExport.mdb bit - i thought i'd cracked it... but it then doesnt like the TODAYS~1
Any other way of finding the app path?
Jza
#4
Don't hard code it, add another table called "configuration" with fields "name" and "value", then make an entry with values "export_path" and "c:\whatever\wherever\"
write your file to =dlookup("[value]","configuration", "[name]=""export_path""" & "data.mdb"
Any use?
Nick.
write your file to =dlookup("[value]","configuration", "[name]=""export_path""" & "data.mdb"
Any use?
Nick.
#6
Thanks Nick... but i want to be able to copy the .mdb etc into any directory - and then it automatically know where to look without me having to do anything.....
Jza
Jza
#7
Below is the code I am using to automatically link the database front end to the backend tables in another .mdb file. This works perfectly with long directory names.
---------------------
Private Sub Form_Load()
On Error GoTo Err_Form_Load
Dim db As Database
Dim ts As TableDefs
Dim t As TableDef
Dim path As String
Dim tstring As String
Set db = CurrentDb
Set ts = db.TableDefs
path = db.Name
If Len(path) > 4 Then
path = ";DATABASE=" & Left(path, Len(path) - 4) & "t.mdb"
Else
MsgBox ("error")
End If
For Each t In ts
If Not ((t.Name = "MSysAccessObjects") Or _
(t.Name = "MSysACEs") Or _
(t.Name = "MSysCmdbars") Or _
(t.Name = "MSysObjects") Or _
(t.Name = "MSysQueries") Or _
(t.Name = "MSysRelationships")) _
Then
t.Connect = path
t.RefreshLink
End If
Next
Exit_Form_Load:
Exit Sub
Err_Form_Load:
tstring = ""
For Each t In ts
If Not ((t.Name = "MSysAccessObjects") Or _
(t.Name = "MSysACEs") Or _
(t.Name = "MSysCmdbars") Or _
(t.Name = "MSysObjects") Or _
(t.Name = "MSysQueries") Or _
(t.Name = "MSysRelationships")) _
Then
tstring = tstring & t.Name & ", "
End If
Next
tstring = Left(tstring, Len(tstring) - 2)
path = Right(path, Len(path) - 10)
MsgBox "Please ensure " & path & " exists containing the following tables. " & tstring, , "Database or Table Missing"
DoCmd.Quit
Resume Exit_Form_Load
End Sub
---------------------
Private Sub Form_Load()
On Error GoTo Err_Form_Load
Dim db As Database
Dim ts As TableDefs
Dim t As TableDef
Dim path As String
Dim tstring As String
Set db = CurrentDb
Set ts = db.TableDefs
path = db.Name
If Len(path) > 4 Then
path = ";DATABASE=" & Left(path, Len(path) - 4) & "t.mdb"
Else
MsgBox ("error")
End If
For Each t In ts
If Not ((t.Name = "MSysAccessObjects") Or _
(t.Name = "MSysACEs") Or _
(t.Name = "MSysCmdbars") Or _
(t.Name = "MSysObjects") Or _
(t.Name = "MSysQueries") Or _
(t.Name = "MSysRelationships")) _
Then
t.Connect = path
t.RefreshLink
End If
Next
Exit_Form_Load:
Exit Sub
Err_Form_Load:
tstring = ""
For Each t In ts
If Not ((t.Name = "MSysAccessObjects") Or _
(t.Name = "MSysACEs") Or _
(t.Name = "MSysCmdbars") Or _
(t.Name = "MSysObjects") Or _
(t.Name = "MSysQueries") Or _
(t.Name = "MSysRelationships")) _
Then
tstring = tstring & t.Name & ", "
End If
Next
tstring = Left(tstring, Len(tstring) - 2)
path = Right(path, Len(path) - 10)
MsgBox "Please ensure " & path & " exists containing the following tables. " & tstring, , "Database or Table Missing"
DoCmd.Quit
Resume Exit_Form_Load
End Sub
Trending Topics
Thread
Thread Starter
Forum
Replies
Last Post