Question : Relink Backend Programmatically

I built a client a frontend and backend database.  The client wants some changes made to the front end.  They want to email it to me and me to email it back.  I have an older backend here that I can link to.  However, when I send the frontend back, I need for them to relink to the backend programmatically.  The person operating the database doesn't know anything about Access databases.  How should I handle this?  Thanks.

Answer : Relink Backend Programmatically

Here are two functions I use
-----------------------------------------------------------------------------------------------------------------
Public Sub Link()
On Error GoTo error_code

Dim strSQL As String
Dim tbl As ADOX.Table
Dim intI As Integer
Dim cat As ADOX.Catalog
Dim strDB As String

    'link to db1.mdb
    Set cat = New ADOX.Catalog
    Set tbl = New ADOX.Table
   
    strDB = CurrentProject.Path & "\" & "db1.mdb"
    cat.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=" & strDB & ";"
       
    For Each tbl In cat.Tables
            DoCmd.TransferDatabase acLink, "Microsoft Access", strDB, acTable, tbl.Name, tbl.Name, False
    Next tbl
    Set cat = Nothing
    Set tbl = Nothing
   
    'link to d2.mdb
    Set cat = New ADOX.Catalog
    Set tbl = New ADOX.Table
   
    strDB = CurrentProject.Path & "\" & "db2.mdb"
    cat.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=" & strDB & ";"
   
    For Each tbl In cat.Tables
            DoCmd.TransferDatabase acLink, "Microsoft Access", strDB, acTable, tbl.Name, tbl.Name, False
    Next tbl
    Set cat = Nothing
    Set tbl = Nothing

   
cleanup_code:
    On Error Resume Next
    Set cat = Nothing
    Set tbl = Nothing

exit_code:
    Exit Sub
   
error_code:
    Select Case Err.Number
        Case 3011
            Resume Next
           
        Case Else
            Resume exit_code
    End Select

End Sub
-----------------------------------------------------------------------------------------------------------------
Public Sub unLink()
On Error GoTo error_code

Dim cat As ADOX.Catalog
Dim tbl As ADOX.Table

Set cat = New ADOX.Catalog
Set tbl = New ADOX.Table
cat.ActiveConnection = CurrentProject.Connection
For Each tbl In cat.Tables
    If tbl.Type = "LINK" Then
        DoCmd.DeleteObject acTable, tbl.Name
    End If
Next tbl

cleanup_code:
    On Error Resume Next
    Set cat = Nothing
    Set tbl = Nothing

exit_code:
    Exit Sub
   
error_code:
    Resume exit_code

End Sub
-----------------------------------------------------------------------------------------------------------------

always run unlink first it wil remove any existing linked tables then run link and it will link the tables. These delete the links not the tables...

You will also need to add Microsoft ADO Ext xxx for DLL and Security in the Tools / references menu in the VBA window.

Cheers
Steve
Random Solutions  
 
programming4us programming4us