Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Prompt to update linked table location in VBA

Posted on 2011-02-27
4
Medium Priority
?
251 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
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…
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 …

722 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