Forum Discussion
Using Access Database on Two Computers [Case #:1053617826] Microsoft Support
- May 25, 2023
Hi,
I have a client who has his frontend and backend always in the same folder but sometimes copies both files to different computers and thus different paths. So we relink the backend tables every time he starts the application to the folder path of the frontend. Your problem seems similar and could probably be solved = automated with a similar technique:
1. Create a new VBA module in the frontend.
2. Copy this function into the module:
Public Function fctLinkedTablePaths() On Error GoTo myError Dim db As DAO.Database Dim tdf As DAO.TableDef Dim strDbFile As String Set db = CurrentDb For Each tdf In db.TableDefs If tdf.Connect <> "" Then strDbFile = Mid(tdf.Connect, InStrRev(tdf.Connect, "\")) tdf.Connect = ";database=" & CurrentProject.Path & strDbFile tdf.RefreshLink End If Next tdf myExit: Exit Function myError: Select Case Err.Number Case 9999 'trap specific errors Case Else MsgBox "Exception No. " & Err.Number & ". " & Err.Description Resume myExit End Select End Function3. Create a new macro called: AutoExec
4. In the macro choose the action: RunCode
and as Function Name: =fctLinkedTablePaths()
Servus
Karl
****************
Access Bug Trackers
Access News
Access DevCon
Here's what it looks like on the main computer (see attached).
I really only need a couple of those linked at the new location, but I'm reluctant to start messing around too much and potentially screwing things up at both locations and having to redo it. I have limited expertise in this linkage feature beyond this application. I don't want to create new problems. Thanks for your help so far. Wayne
Hi,
I have a client who has his frontend and backend always in the same folder but sometimes copies both files to different computers and thus different paths. So we relink the backend tables every time he starts the application to the folder path of the frontend. Your problem seems similar and could probably be solved = automated with a similar technique:
1. Create a new VBA module in the frontend.
2. Copy this function into the module:
Public Function fctLinkedTablePaths()
On Error GoTo myError
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim strDbFile As String
Set db = CurrentDb
For Each tdf In db.TableDefs
If tdf.Connect <> "" Then
strDbFile = Mid(tdf.Connect, InStrRev(tdf.Connect, "\"))
tdf.Connect = ";database=" & CurrentProject.Path & strDbFile
tdf.RefreshLink
End If
Next tdf
myExit:
Exit Function
myError:
Select Case Err.Number
Case 9999
'trap specific errors
Case Else
MsgBox "Exception No. " & Err.Number & ". " & Err.Description
Resume myExit
End Select
End Function
3. Create a new macro called: AutoExec
4. In the macro choose the action: RunCode
and as Function Name: =fctLinkedTablePaths()
Servus
Karl
****************
Access Bug Trackers
Access News
Access DevCon
- WayneCrimi1Sep 17, 2024Copper Contributor
Karl_Donaubauer This has been working fine for over two years. Last week, my database got corrupted. I believe it was due to size. I deleted some unnecessary tables and queries and was able to get it functyioning well again, except for the AutoExec and function you gave me. It's getting a compile error when I bring up the database. I tried deleting the Autoexec and macro and starting over, but I am getting the same problem. Any suggestions.
- Sep 17, 2024
Hi,
The DAO reference is most likely missing in your VBA project. In the VBA editor select the menu Item Tools - References, in the alphabetically sorted references list look for
Microsoft Office 16.0 Access Database Engine Object Library
and set the tick there.
Servus
Karl
****************
Access Forever, News, DevCon
Access-Entwickler-Konferenz AEK - 19./20.10. Nürnberg- WayneCrimi1Sep 20, 2024Copper ContributorKarl_Donaubauer
I figured out how to get to References.
Holy crap, you got it to work!
You are heroic Karl!
- WayneCrimi1May 25, 2023Copper Contributor
Thanks for the reply.
VBA is over my head. I'm going to have to try to understand it first so I know if I have to change anything, but that sounds like a good solution for automating it.Thanks for your help.
Wayne.
- May 26, 2023
Hi,
You could create a copy of your frontend/main application file, do what I described and thus test if it works for you. The code only does things in this file. So the worst thing that can happen is that sth doesn't work in that copy.
Servus
Karl
****************
Access Bug Trackers
Access News
Access DevCon- WayneCrimi1May 26, 2023Copper Contributor
I more or less understand how it's using the current frontend database and looking for the linkages, but I don't understand how it knows what to change them to. Is is basically just assuming everything its looking for is in the same directory as the main database?
Just trying to understand what its doing before I start testing.
Thanks