Solved

Prompt to update linked table location in VBA

Posted on 2011-02-27
4
240 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
Comment Utility
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
Comment Utility
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

Expert Comment

by:Armen Stein - Microsoft Access MVP since 2006
Comment Utility
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
Comment Utility
Posted solution I found in a different thread.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
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…

744 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

18 Experts available now in Live!

Get 1:1 Help Now