On Feb 20, 6:15*pm, "susan" <duff...@hetnet.nlwrote:
Hi,
My application uses 2 access-mdb's. One (data.mdb) contains the userdata,
the other (appl.mdb) contains forms, code, etc. Ilink form appl.mdb to the
tables of data.mdb.
The problem I fnd is that the links is stored as an absolute path. This
means the user is very restricted in the folder where he/she places the
application.
(How) can I link to a table/mdb with a relative path?
Thanks,
Susan
This is the one I use. I think I got it off this forum. There may be
others, but this works for me.
Function Reconnect()
On Error Resume Next
'************************************************* *************
'* START YOUR APPLICATION (MACRO: AUTOEXEC) WITH THIS FUNCTION
'* AND THIS PROGRAM WILL CHANGE THE CONNECTIONS AUTOMATICALLY
'* WHEN THE 'DATA.MDB' AND THE 'PRG.MDB'
'* ARE IN THE SAME DIRECTORY!!!
'* PROGRAMMING BY PETER VUKOVIC, Germany
'*
10*********@compuserve.com
'* ************************************************** **********
Dim db As Database, Source As String, path As String
Dim dbsource As String, i As Integer, j As Integer
Set db = DBEngine.Workspaces(0).Databases(0)
'************************************************* ************
'* RECOGNIZE THE PATH *
'************************************************* ************
For i = Len(db.Name) To 1 Step -1
If Mid(db.Name, i, 1) = Chr(92) Then
path = Mid(db.Name, 1, i)
'MsgBox (path)
Exit For
End If
Next
'************************************************* ************
'* CHANGE THE PATH AND CONNECT AGAIN *
'************************************************* ************
For i = 0 To db.TableDefs.Count - 1
If db.TableDefs(i).Connect <" " Then
Source = Mid(db.TableDefs(i).Connect, 11)
'Debug.Print source
For j = Len(Source) To 1 Step -1
If Mid(Source, j, 1) = Chr(92) Then
dbsource = Mid(Source, j + 1, Len(Source))
Source = Mid(Source, 1, j)
If Source <path Then
db.TableDefs(i).Connect = ";Database=" + path
+ dbsource
db.TableDefs(i).RefreshLink
'Debug.Print ";Database=" + path + dbsource
End If
Exit For
End If
Next
End If
Next
End Function
Hope this helps.