Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Importing / Linking / January 2008

Tip: Looking for answers? Try searching our database.

linking tables to external ones?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Howard - 27 Jan 2008 19:20 GMT
My database links to two tables in another access database and also to
two excel spreadsheets. At work these and the 'main' database are all in
the same folder with other stuff. However I often put this entire folder
on a memory stick and/or copy it to my laptop to work on.

Is there a way I can set up the linking so that it will always look in
the folder where the 'main' database is without having to manually
re-link each thing separately? (something like application.path in VB)

Especially as the linked table wizard window is too small to see all of
the long pathnames in modern machines.

Howard

(cross posted also to the tables forum - apologies)
Douglas J. Steele - 27 Jan 2008 19:33 GMT
Here's code I have in the Load event of the first form to open in one of my
databases:

Private Sub Form_Load()
' Check that the front-end is linked to a back-end
On Error GoTo Err_Form_Load

Dim dbCurr As DAO.Database
Dim tdfCurr As DAO.TableDef
Dim strCurrLinkage As String
Dim strFrontendPath As String
Dim strExpectedBackend As String

 Set dbCurr = CurrentDb()
 strFrontendPath = Application.CurrentProject.Path
 If Right(strFrontendPath, 1) <> "\" Then
   strFrontendPath = strFrontendPath & "\"
 End If
 strExpectedBackend = ";Database=" & strFrontendPath & "CollectionData.mdb"

' Make the simplifying assumption that all linked tables
' will point to the same back-end
 For Each tdfCurr In dbCurr.TableDefs
   With tdfCurr
     strCurrLinkage = .Connect
     If Len(strCurrLinkage) > 0 Then
       If StrComp(strCurrLinkage, strExpectedBackend, vbTextCompare) <> 0
Then
         .Connect = strExpectedBackend
         .RefreshLink
       End If
     End If
   End With
 Next tdfCurr

End_Form_Load:
   Exit Sub

Err_Form_Load:
   MsgBox Err.Number & ": " & Err.Description
   Resume End_Form_Load

End Sub

Now, you wouldn't be able to make the simplifying assumption I made, but you
can modify that section a little to allow you to reset different tables to
point to different locations.

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)

> My database links to two tables in another access database and also to two
> excel spreadsheets. At work these and the 'main' database are all in the
[quoted text clipped - 11 lines]
>
> (cross posted also to the tables forum - apologies)
Howard - 27 Jan 2008 20:40 GMT
Thank you Douglas,
I think I can see how to add my excel sheets into that as well.
It will save some time in the long run.
Howard

> Here's code I have in the Load event of the first form to open in one of my
> databases:
[quoted text clipped - 43 lines]
> can modify that section a little to allow you to reset different tables to
> point to different locations.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.