Question : Access 2000 Relink front-end to back-end tables using a path supplied by an .ini file

I have a classic FE/BE where the FE db is in a folder Applications, and all of the various customer BE db files are in a folder called Data Files.  The Data Files folder has sub folders for each customer (Customer A, Customer B, etc.).  The BE file structure is the same for all customer BE data files.  There is a path.ini file in the same folder as the FE which holds a single text line with the path to the particular customer BE.  This make it easy to change the BE path by just altering the path.ini before opening the FE app.  However, sometimes the relink process doesn't run completely and I have some links to customer A and some to customer B.  I want to force a relink every time the FE app is opened, and perhaps streamline the code a bit.  Thanks
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
Public Function fRefreshAllLinks() As Boolean
    On Error GoTo Handle_Err
    'Created by RO on 4/23/2009
    Const conProcName As String = conModuleName & ".fRefreshAllLinks"
    '/ Forces a refresh of ALL table links between FE and BE
    '/ This assumes that tblSoftwareUserBE has already been refreshed properly
 
    Dim db As DAO.Database
    Dim tdf As DAO.TableDef
    Dim strConn As String             ' first part of tdf.connect connection string
    Dim strDB As String                 ' second part of tdf.connect = path to the backend database
    Dim strConnect As String         ' assembled connection string
    Dim strWrongDB As String        ' name of the backend db incorrectly linked to
    Dim intTableCount As Integer    ' count of all linked application tables
    Dim intBadLinks As Integer       ' count of tables with bad links
    Dim intStillBadLinks As Integer      ' count of corrected links
        Set db = CurrentDb()
 
    '/ Initialize return variable
    fRefreshAllLinks = False
    
    intTableCount = 0
    intBadLinks = 0
    intStillBadLinks = 0
    
  '/ Get the back end path from Harvest.ini
    strDB = fGetINIdbPath
    
    '/ Creat the first part of the connection string
    strConn = "MS Access;PWD=bluebird;DATABASE="
'Debug.Print strdb
 
    '/ Assemble entire connection string
    strConnect = strConn & strDB
Debug.Print "The INI Path is :  " & strConnect
   
    '/ Loop thru the tables collection
    For Each tdf In db.TableDefs
        '/ Just look at the Harvest application tables (start with tbl)  atbl is ONLY front-end
        ' COMEBACK WHAT ABOUT USYSUBE ?
        
        If Left(tdf.Name, 3) = "tbl" Then
        intTableCount = intTableCount + 1
            '/ Check the table's connect property
            If Len(tdf.Connect) > 0 Then
Debug.Print intTableCount & " " & tdf.Name & " - " & tdf.Connect
            Else
        Debug.Print "BAD FILE    " & tdf.Name & " - " & tdf.Connect
                If tdf.Connect <> strConnect Then
                    intBadLinks = intBadLinks + 1
Debug.Print intBadLinks
                    tdf.Connect = strConnect
                    tdf.RefreshLink
                    '/ Try it again
                    If tdf.Connect <> strConnect Then
                        '/ Name of wrong DB
                        strWrongDB = strConnect
                        intStillBadLinks = intStillBadLinks + 1
Debug.Print " **************" & tdf.Name & " - " & tdf.Connect & " ************"
                    End If
                End If
            End If
        End If
    Next tdf
 
    If intStillBadLinks = 0 Then
        fRefreshAllLinks = True
    Else
        fRefreshAllLinks = False
    End If
    
    Set tdf = Nothing
 
exit_here:
    Exit Function
Handle_Err:
    Select Case Err.Number
       Case Else
            MsgBox "Error: basUtilities - Function fRefreshAllLinks: " & Err.Number & " " & Err.Description, _
                        vbCritical + vbOKOnly, "Harvest error message"
            HandleUntrappedError conProcName
    End Select
    Resume exit_here
    Resume
End Function

Answer : Access 2000 Relink front-end to back-end tables using a path supplied by an .ini file

Which B/E code are you using, the code snippet I gave you from aadconsulting, or the code you got from Andy Barron?

One thing I did notice is that you are using mapped drive letters in your path.  You need to use UNC in your path.  If you use UNC paths, you should be able to avoid the problem with the new table being linked to the old Current Db,  Below is an excerpt from the link I gave you to Albert Kallal's article on splitting your Access db into FE and BE components.

"One last thing about linking the FE to the BE is that you need to always use what is called UNC path names (Universal Naming Convention). All this really means is that you REALLY REALLY REALLY do not want to use mapped drive letters when you link.  Mapped letters are a 20 year throwback to the old PC DOS and CPM days when we used floppy disks! (When is the last time you used a floppy disk). Don't use mapped drives to a file share on the server. Drive mappings have all kinds of problems. Just plugging in a USB jump drive (memory stick) into your computer and the drive mappings can change. Further, you have to setup EACH pc for drive mappings and that is a pain. Further, even plugging in a digital camera can change drive letters. So, just avoid drive letters and mapping like the plague. Simply put, don't use them, and they are horrible from a support point of view. If you do risk using drive letters, then you will get a large increase in support calls for your software.

In other words, always use a path name to the back end files. What this means is when you use the linked table manger, always navigate through network places to the server, and then to the folder, and then the back end mdb file. DO NOT use mapped drives, and do NOT use the linked table manager to navigate to a back end by a drive letter.  If you use a mapped drive, then your path name will be something like:

e:\mydata\backend.mdb

If you navigate by the network places, you will get a path name that does NOT have a drive letter. The path name (UNC) will look like

\\servername\mydata\backend.mdb

Random Solutions  
 
programming4us programming4us