Solved

Prompt to update linked table location in VBA

Posted on 2011-02-27
4
247 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
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…

734 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