Solved

Prompt to update linked table location in VBA

Posted on 2011-02-27
4
245 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

830 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