Solved

Prompt to update linked table location in VBA

Posted on 2011-02-27
4
241 Views
Last Modified: 2012-05-11
I have a database with a linked table for the backend.  When I open the database and the location to the backend can't be found the program errors out.  Is there a way to get it to prompt me so I can tell it where the database is without having to go into the linked table manager?
0
Comment
Question by:threeieng
  • 2
4 Comments
 
LVL 77

Expert Comment

by:peter57r
ID: 34991364
There is some comprehensive and well used code here:
http://www.mvps.org/access/tables/tbl0009.htm

Note that you need to get other code as well,  as is indicated in the intro.
0
 

Accepted Solution

by:
threeieng earned 0 total points
ID: 34997844
I found this code in a different thread.  Molded it to my needs. Thanks:
Option Compare Database
Option Explicit

'+---------------------------------------------------------------------------+
'| Version: 6.1                   Programmed by: The Computer Mentor    |
'| Dated  : 10/20/2010                                                                 |
'+---------------------------------------------------------------------------+

Public zStatusMsg     As String
Public lTimerInterval As Long
Public Const zCodeVersionNo = "6.1"

'                            +------------------+                 +----------+
'--------------- -------|  ReLinkTable()   |--------------| 10/20/10 |
'                            +------------------+                 +----------+
'Called by: Macro - AutoExec
'Calls    : [Utilities] zGetDBPath()
'Globals  : lTimerInterval
'           zStatusMsg
'Notes    : 03/04/10 - Added timed relink message vs msgbox w/user action
'           06/04/10 - Added shared access for Office Computers P-P Lan
'           06/10/10 - Addes shared access for Computer Mentor P-P Lan

Function ReLinkTable()

   Dim zDBPath             As String
   Dim zDBFullName      As String
   Dim zBEDBFN           As String
   Dim zTableName(12) As String
   Dim iTblCnt              As Integer
   
   GoTo StartLinking

FileDoesNotExist:

   If Err.Number = 7874 Then
     Resume Next
   Else
     MsgBox "Error No: " & Err.Number & vbCrLf & _
            "Description: " & Err.Description
   End If

StartLinking:

   zTableName(0) = "Docks"
   zTableName(1) = "Lots"
   zTableName(2) = "Owners"
   zTableName(3) = "PhoneDir"
   zTableName(4) = "StorageLots"
   zTableName(5) = "tblAuxNumbers"  '*** Last table in ARB_be.mdb       ***
   zTableName(6) = "Builders"       '*** Start of tables in ARBReqs.mdb use index in If iTblCnt = below***
   zTableName(7) = "Letters"
   zTableName(8) = "ARBMembers"
   zTableName(9) = "ARBAssignments"
   zTableName(10) = "Requests"
   zTableName(11) = "RequestTypes"
   
   zDBPath = zGetDBPath()
   
   If zDBPath = "Error" Then
     MsgBox Environ("USERNAME") & ": is not an authroized user!", _
                vbOKOnly + vbCritical, "Error: User Not Authorized"
     ExitDB
   End If
   
   zBEDBFN = "ARB_be.mdb"
   zDBFullName = zDBPath & zBEDBFN
  
   For iTblCnt = 0 To UBound(zTableName) - 1
   
      If iTblCnt = 6 Then            '*** Switch back end DB files ***
        zBEDBFN = "ARBReqs_be.mdb"
        zDBFullName = zDBPath & zBEDBFN
      End If
      
      On Error GoTo FileDoesNotExist
      '*** Delete TableDef from FRONT end DB
      DoCmd.DeleteObject ObjectType:=acTable, ObjectName:=zTableName(iTblCnt)
   
      '*** Copy TableDef from BACK end DB to FRONT end DB - Keep in sync!
      DoCmd.TransferDatabase TransferType:=acLink, _
                             DatabaseType:="Microsoft Access", _
                             DatabaseName:=zDBFullName, _
                               ObjectType:=acTable, _
                                   Source:=zTableName(iTblCnt), _
                              Destination:=zTableName(iTblCnt)
      On Error GoTo 0
      
   Next iTblCnt
                             
    zStatusMsg = "Tables have been Re-Linked"
    lTimerInterval = 3000    '*** 3 Seconds ***
    DoCmd.OpenForm "frmStatusMsg", acNormal
    Application.SetOption "Themed Form Controls", False
    StdMenuToggle "False"
    
End Function    'ReLinkTable()

'                          +---------------------+                 +----------+
'--------------------------|    zGetDBPath()     |-----------------| 10/20/10 |
'                          +---------------------+                 +----------+
'Called by: [RelinkTables] RelinkTable()
'Returns  : STRING = Path to backend DB based on user name and machine name.

Public Function zGetDBPath() As String

   Dim zUName    As String
   Dim zCompName As String
   
   zUName = Environ("USERNAME")
   Select Case zUName
     Case "Bruce"
         zCompName = Environ("COMPUTERNAME")
         If zCompName = "INSPIRON15-I5" Then                     '*** BEK Laptop     ***
           zGetDBPath = "G:\bekdocs\ARB Files\"                  '*** Laptop         ***
         Else                                                    '*** BEK Desktop    ***
           zGetDBPath = "G:\bekdocs\ARB Files\"                  '*** Winows 7 Path  ***
         End If
     Case "Owner"                                                '*** BEKHP        ***
         zGetDBPath = "\\BEK-PC\BEKDocs\ARB Files\"           '*** Network Path   ***
     Case "Wyboo Manager"                                        '*** Harry          ***
         zGetDBPath = _
             "C:\Users\Wyboo Manager\Documents\ARB Files\"       '*** Windows 7 Path ***
     Case "Property Manager"                                     '*** Martin         ***
         zGetDBPath = "\\Wyboomanager-pc\ARB Files\"             '*** Network Path   ***
     Case Else
         zGetDBPath = "Error"

   End Select

End Function    '*** zGetDBPath() **

Open in new window

0
 
LVL 9
ID: 34999898
I know this is already answered,  but here's another alternative that doesn't require any additional code.  You're welcome to use our free J Street Access Relinker on our J Street Downloads page:  http://ow.ly/M56Q

It's some simple code that you copy into your front-end application.  It handles multiple Access back-end databases, ignores non-Access tables, and can automatically and silently relink to back-end databases in the same folder as the application (handy for work databases or single-user scenarios).  There's a ReadMe table with instructions.

Cheers,
Armen
0
 

Author Closing Comment

by:threeieng
ID: 35042472
Posted solution I found in a different thread.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now