Results 1 to 4 of 4
  1. #1
    vicsaccess's Avatar
    vicsaccess is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Apr 2015
    Posts
    451

    FE relinking


    i have a FE with a version checker that automatically updates the users FE if the versions our different, nothing new there, many of you helped me put it together. Now what I'm finding is that for a few of my users the new FE is loosing its links to the BE when they start it up for the first time after the update. Is there a way to either automatically or with a command button relink to the BE? its a simple procedure to relink but i would prefer to not have my users messing with the ribbon commands. so far the research I've done comes up with a few codes that are several pages long that is beyond my current knowledge or i did find one that was shorter and workable but it was to change the path. any suggestions would be appreciated.

  2. #2
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,791
    I stopped using this; can't remember why for sure but I think it was because I deemed it unnecessary after I opted to shutdown if the user had a rouge copy. Tweak it as you need (you will probably removed the user interaction part and just do the relink), keeping in mind the db was a shared single db due to network constraints. That's why there is a part that 'worries' about someone else being logged in.

    RelinkByList [call to the function from somewhere in code]

    Code:
    Function RelinkByList()
    'loops thru table tblLinkedTables & compares current link to tblLinkedTables path value
    'to ensure links to BE are checked after a database is replaced by a new version
    Dim db As DAO.Database
    Dim rst As DAO.Recordset
    Dim tdf As DAO.TableDef
    Dim currConnect As String, trgtConnect As String, msg As String, tblName As String
    Dim result As Integer
    Dim Warned As Boolean
    
    On Error GoTo errHandler
    Set db = CurrentDb
    Set rst = db.OpenRecordset("tblLinkedTables", dbOpenSnapshot)
    rst.MoveFirst
    
    Do Until rst.EOF
    tblName = rst.Fields("TableName")
    Set tdf = db.TableDefs(tblName)
    'curConnect is current connection value, trgtConnect is path stored in tblLinkedTables
    'if network structure ever changes, 11 may have to be altered to display path properly
    currConnect = Nz(Mid(tdf.Connect, 11), "")
    trgtConnect = Nz(rst!DataFilePath, "")
    
    If trgtConnect <> currConnect Then
        msg = "Current mapping appears incorrect for '" & tblName & "'." & vbCrLf
        msg = msg & "Re-link this table? CLICK CANCEL TO STOP CHECKING ALL TABLES."
        msg = msg & vbCrLf & vbCrLf
        msg = msg & "Expected path: " & vbCrLf & trgtConnect & vbCrLf & vbCrLf
        msg = msg & "Current path: " & vbCrLf & currConnect
        result = MsgBox(msg, vbYesNoCancel, "CHECKING TABLE CONNECTIONS")
            If result = 2 Then
                Set tdf = Nothing
                Set rst = Nothing
                Set db = Nothing
                Exit Function
            End If
            If result = 7 Then rst.MoveNext 'user said don't change this link
            If result = 6 And LoggedInCount > 1 Then 'user chose to change but others logged in
                If Warned = False Then 'this is the first warning re: logged in users
                    msg = "OTHERS APPEAR TO BE LOGGED IN!" & vbCrLf
                    msg = msg & "Remapping tables may cause them to lose data." & vbCrLf
                    msg = msg & "Continue anyway?"
                    result = MsgBox(msg, 52, "LOGGED IN COUNT = " & LoggedInCount)
                    Warned = True
                    'DoCmd.OpenForm "frmWait"
                    'Pause (1) 'without pause, frmWait does not completely display
                    If result = 6 Then 'user said to change link anyway
                        tdf.Connect = ";DATABASE=" & trgtConnect
                        tdf.RefreshLink
                    End If
                    If result = 7 Then GoTo exitHere 'user chose not to change link
                End If
            End If
            If result = 6 And LoggedInCount < 2 Then
                tdf.Connect = ";DATABASE=" & trgtConnect
                tdf.RefreshLink
            End If
          'DoCmd.Close acForm, "frmWait"
    End If
    ''If trgtConnect = "" Then
    ''    MsgBox "Cannot re-link " & tblName & ": No path specified in table tblLinkedTables.", "TABLE PATH MISSING"
    ''    'Resume Next
    ''End If
    LoopHere:
    rst.MoveNext
    Loop
    
    exitHere:
      Set tdf = Nothing
      Set rst = Nothing
      Set db = Nothing
    Exit Function
    
    errHandler:
    If Err.Number = 3265 Then
        msg = "Table '" & tblName & "' not found in list of linked tables." & vbCrLf
        msg = msg & "The table may be missing from database or mis-spelled" & vbCrLf
        msg = msg & " in list of linked tables." & vbCrLf & vbCrLf
        msg = msg & "Please call a database administrator to check tables information."
        MsgBox msg, vbOKOnly, "TABLE NOT FOUND"
        Resume LoopHere
    End If
    If Err.Number = 3321 Then
        msg = "Cannot re-link " & tblName & ": No path specified in table tblLinkedTables."
        msg = msg & vbCrLf & "Please call a database administrator to check tables information."
        MsgBox msg, vbOKOnly, "TABLE PATH MISSING"
        Resume LoopHere
    End If
    MsgBox "Error number " & Err.Number & ": " & Err.Description
    
    'If Err.Number = 3734 Or Err.Number = 2450 Then Resume exitHere
    
    End Function
    In case you need the code for the called Pause

    Code:
    Public Function Pause(intSecs As Integer)
    Dim Start As Variant
    Start = Timer
    Do While Timer < Start + intSecs
        DoEvents
    Loop
    End Function
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    vicsaccess's Avatar
    vicsaccess is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Apr 2015
    Posts
    451
    thank you micron, looks like just what i was looking for.

  4. #4
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,791
    Welcome! Hope you get it to work.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Relinking Tables
    By crowegreg in forum Access
    Replies: 2
    Last Post: 10-09-2013, 05:56 PM
  2. Replies: 4
    Last Post: 06-04-2013, 01:13 PM
  3. relinking backend
    By togo in forum Access
    Replies: 1
    Last Post: 12-10-2012, 11:24 AM
  4. avoid relinking linked tables
    By Hobbes29 in forum Import/Export Data
    Replies: 1
    Last Post: 10-01-2010, 11:15 PM
  5. Relinking an ADE file to SQL tables
    By cjbuechler in forum Database Design
    Replies: 4
    Last Post: 06-05-2009, 09:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums