Connecting Tech Pros Worldwide Forums | Help | Site Map

Linking Tables in Access

John Ortt
Guest
 
Posts: n/a
#1: Nov 13 '05
Hi Everyone,

Just wonderring if it is possible to link tables in access using 'relative'
terminology rather than 'absolute' ?

For example the path would become '\Sourcefile\MyPets.mdb' rather than
'C:\folders\Sourcefile\MyPets.mdb'.

The beauty of this type of referencing (if possible) is that I would be able
to have two copies, a development copy and a live copy and not have to worry
about the links (provided I maintained the same lower folder structure).

If I have explained poorly or you want more info please feel free to ask.
Equally if you know the answer to the question of whether it is possible I
would also appreciate it.

Thanks,

John


Keith
Guest
 
Posts: n/a
#2: Nov 13 '05

re: Linking Tables in Access


"John Ortt" <johnortt@noemailsuppliedasdontwantspam.com> wrote in message
news:432052e0$1_1@glkas0286.greenlnk.net...[color=blue]
> Hi Everyone,
>
> Just wonderring if it is possible to link tables in access using
> 'relative' terminology rather than 'absolute' ?
>
> For example the path would become '\Sourcefile\MyPets.mdb' rather than
> 'C:\folders\Sourcefile\MyPets.mdb'.
>[/color]
Do you mean in code? You could always set a string variable to contain the
path - is this what you're getting at?

Regards,
Keith.
www.keithwilby.com


John Ortt
Guest
 
Posts: n/a
#3: Nov 13 '05

re: Linking Tables in Access



"Keith" <keith.wilby@baeAWAYWITHITsystems.com> wrote in message
news:432055d8$1_1@glkas0286.greenlnk.net...[color=blue]
> "John Ortt" <johnortt@noemailsuppliedasdontwantspam.com> wrote in message
> news:432052e0$1_1@glkas0286.greenlnk.net...[color=green]
>> Hi Everyone,
>>
>> Just wonderring if it is possible to link tables in access using
>> 'relative' terminology rather than 'absolute' ?
>>
>> For example the path would become '\Sourcefile\MyPets.mdb' rather than
>> 'C:\folders\Sourcefile\MyPets.mdb'.
>>[/color]
> Do you mean in code? You could always set a string variable to contain
> the path - is this what you're getting at?
>[/color]
Not quite Keith, I found the code at the bottom of the post previously and
it has been extremely useful, particularly for removing mapped drive letter
and replacing them with server names which ensures people with different
mappings can still access the files.
What I am wonderring is if I can use a partial path (ie. relative to the
folder location of the database in use).
I ask this based on the ability to do it with html. For instance you can
either say the full path for the location of an image or you can give it
relative to the current folder.

Hope that makes sense,

John.


Option Compare Database
Option Explicit

Function ChangeLinksCode()
Dim Db As DAO.Database
Dim tbl As DAO.TableDef
Dim oldBE As String
Dim newBE As String
Dim i As Integer
Dim tbln As String
Dim lnk As String
Dim Check As String

Set Db = CurrentDb() 'Announces that the code works on this database


oldBE = "P:\"
newBE = "\\Maasams01\Projects\"

'The two lines above give the location of the old file path (oldBE)
'and then the desired location of the new file path (newBE)

'The following code loops from i=0 (Line 1) until the last line of the table
definitions (db.TableDefs.Count - 1)
'It checks that the link is to a database (Left(lnk, 9) = ";DATABASE")
'and if so replaces all instances of the oldpath with the new one

For i = 0 To Db.TableDefs.Count - 1
tbln = Db.TableDefs(i).Name
Set tbl = Db.TableDefs(tbln)
lnk = tbl.Connect
Check = tbl.Connect
If Left(lnk, 9) = ";DATABASE" Then
lnk = Replace(lnk, oldBE, newBE)
If lnk <> Check Then
tbl.Connect = ""
tbl.Connect = lnk
tbl.RefreshLink
End If
End If
Next

'The next section of the code repeats that above but for non database files
(i.e. text and excel files)

oldBE = "P:\"
newBE = "\\Maasams01\Projects\"

For i = 0 To Db.TableDefs.Count - 1
tbln = Db.TableDefs(i).Name
Set tbl = Db.TableDefs(tbln)
lnk = tbl.Connect
Check = tbl.Connect
If Left(lnk, 9) <> ";DATABASE" Then
lnk = Replace(lnk, oldBE, newBE)
If lnk <> Check Then
tbl.Connect = ""
tbl.Connect = lnk
tbl.RefreshLink
End If
End If
Next

End Function


Function Replace(ByVal Valuein As String, ByVal WhatToReplace As
String, ByVal Replacevalue As String) As String
Dim Temp As String, P As Long
Temp = Valuein
P = InStr(Temp, WhatToReplace)
Do While P > 0
Temp = Left(Temp, P - 1) & Replacevalue & Mid(Temp, P +
Len(WhatToReplace))
P = InStr(P + Len(Replacevalue), Temp, WhatToReplace, 1)
Loop
Replace = Temp
End Function


Keith
Guest
 
Posts: n/a
#4: Nov 13 '05

re: Linking Tables in Access


"John Ortt" <johnortt@noemailsuppliedasdontwantspam.com> wrote in message
news:4320588d$1_1@glkas0286.greenlnk.net...[color=blue]
>
> "Keith" <keith.wilby@baeAWAYWITHITsystems.com> wrote in message
> news:432055d8$1_1@glkas0286.greenlnk.net...[color=green]
>> "John Ortt" <johnortt@noemailsuppliedasdontwantspam.com> wrote in message
>> news:432052e0$1_1@glkas0286.greenlnk.net...[color=darkred]
>>> Hi Everyone,
>>>
>>> Just wonderring if it is possible to link tables in access using
>>> 'relative' terminology rather than 'absolute' ?
>>>
>>> For example the path would become '\Sourcefile\MyPets.mdb' rather than
>>> 'C:\folders\Sourcefile\MyPets.mdb'.
>>>[/color]
>> Do you mean in code? You could always set a string variable to contain
>> the path - is this what you're getting at?
>>[/color]
> Not quite Keith, I found the code at the bottom of the post previously
> and it has been extremely useful, particularly for removing mapped drive
> letter and replacing them with server names which ensures people with
> different mappings can still access the files.
> What I am wonderring is if I can use a partial path (ie. relative to the
> folder location of the database in use).
> I ask this based on the ability to do it with html. For instance you can
> either say the full path for the location of an image or you can give it
> relative to the current folder.
>
> Hope that makes sense,
>[/color]
Hmm ... yes I think I know what you mean but I've never heard of any method
from within VBA but I'm sure someone will jump in and correct me ...


David Mann
Guest
 
Posts: n/a
#5: Nov 13 '05

re: Linking Tables in Access



"Keith" <keith.wilby@baeAWAYWITHITsystems.com> wrote in message
news:43206005$1_1@glkas0286.greenlnk.net...[color=blue]
> "John Ortt" <johnortt@noemailsuppliedasdontwantspam.com> wrote in message
> news:4320588d$1_1@glkas0286.greenlnk.net...[color=green]
> >
> > "Keith" <keith.wilby@baeAWAYWITHITsystems.com> wrote in message
> > news:432055d8$1_1@glkas0286.greenlnk.net...[color=darkred]
> >> "John Ortt" <johnortt@noemailsuppliedasdontwantspam.com> wrote in[/color][/color][/color]
message[color=blue][color=green][color=darkred]
> >> news:432052e0$1_1@glkas0286.greenlnk.net...
> >>> Hi Everyone,
> >>>
> >>> Just wonderring if it is possible to link tables in access using
> >>> 'relative' terminology rather than 'absolute' ?
> >>>
> >>> For example the path would become '\Sourcefile\MyPets.mdb' rather[/color][/color][/color]
than[color=blue][color=green][color=darkred]
> >>> 'C:\folders\Sourcefile\MyPets.mdb'.
> >>>
> >> Do you mean in code? You could always set a string variable to contain
> >> the path - is this what you're getting at?
> >>[/color]
> > Not quite Keith, I found the code at the bottom of the post previously
> > and it has been extremely useful, particularly for removing mapped drive
> > letter and replacing them with server names which ensures people with
> > different mappings can still access the files.
> > What I am wonderring is if I can use a partial path (ie. relative to the
> > folder location of the database in use).
> > I ask this based on the ability to do it with html. For instance you[/color][/color]
can[color=blue][color=green]
> > either say the full path for the location of an image or you can give it
> > relative to the current folder.
> >
> > Hope that makes sense,
> >[/color]
> Hmm ... yes I think I know what you mean but I've never heard of any[/color]
method[color=blue]
> from within VBA but I'm sure someone will jump in and correct me ...
>[/color]
I don't think Access allows relative paths. So it would not be possible to
move the front and back end files and have them still linked.

However, you can get the current folder in code, and add the relative path
to create the full path you need and then link the tables in code. If you
do this when the front-end is opened, the user will not know any difference
between having the tables linked using a relative path.

David


Closed Thread