Results 1 to 13 of 13
  1. #1
    lmarconi is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Sep 2020
    Location
    Muscat
    Posts
    74

    How to programmatically re-link all tables from BE Database

    Good morning all.
    I would like to know if someone can kindly suggest me how programmatically re-link tables in a front-end database from the back-end database.


    The idea is to create a function to be used in the Autoexec Macro (at start-up) with the following steps:
    1. When the database is open, the system should check if any link table is present. If tables are link, open the database, if not, go to the step 2.
    2. The system re-link all tables from a given path (will never change)
    The reason why I ask this is because i's going to manage the database remotely so, any new revision will be without any linked tables (because i don't have the way to do it remotely) and the link will be done from the user at the first log on.
    Thank you in advance for kindly and usual support, any other suggestion is more then welcome.
    Cheers.
    L.

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,409
    you need to clarify - you said 're-link tables in a front-end database from the back-end database.' and When the database is open, the system should check if any link table is present. If tables are link, open the database, if not, go to the step 2.
    which database? FE or BE?

    If I understand correctly, you do not have access to your clients network, so you a sending out via email/whatever a revised FE? or a revised FE and BE? and the client needs to relink?



  3. #3
    lmarconi is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Sep 2020
    Location
    Muscat
    Posts
    74
    Quote Originally Posted by CJ_London View Post
    you need to clarify - you said 're-link tables in a front-end database from the back-end database.' and When the database is open, the system should check if any link table is present. If tables are link, open the database, if not, go to the step 2.which database? FE or BE?

    If I understand correctly, you do not have access to your clients network, so you a sending out via email/whatever a revised FE? or a revised FE and BE? and the client needs to relink?


    You understand correct, and thanks for answer. When (and if) any modification is required, I will work with the interface only (FE). Then I will send it them back, without linked tables because, as you said, i don't have access to their network and to be sure it use the tables in the BE database (the BE has only tables and is locate in their network server) , i need this process, so to link the BE tables (from their server network) to the FE database i sent with the modification. Hope it is more clear.
    Cheers.

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,778
    Does your back end have a table that contains the path(s) for all tables that would need to be linked? That's where I'd get the paths from then run through all linked tables and relink them. That can also ensure that no one copies a db to their desktop since the db path won't match what's in the table - assuming they can't get at them and modify the path values. One issue could be that users don't have the same drive letter, so you probably should be using UNC paths.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,409
    Suggest tell the client to put the FE in the same folder as the BE. The path to the BE will be the same as the FE (currentproject.path) - you can then have code to relink the tables. As Micron suggests, recommend convert the path to UNC before relinking.

    After that, all depends on how you (or your client) are planning to update individual users, but a good idea to include code in the FE that closes the app if the path is in shared folder to avoid the risk of users using the copy on the server - obviously to run once tables have been relinked

  6. #6
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,112
    Here is how I used to do that, no need to remove the tables when you send back the updated FE; have a settings table in your FE where you save the connection string for the live BE on the client site and the one for your development BE. Same table has a yes\no field to initiate the change and a "target" field (LIVE or TEST).
    You just need to call the custom VBA function from the very first line of the AutoExec macro (if you have a form set as opening form remove that and do it in the AutoExec after you re-link because if the form is bound it will interfere with the re-linking).

    See the attached sample for all objects required.

    Cheers,
    Attached Files Attached Files
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  7. #7
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,112
    Sorry, forgot to mention that if you want to see how the connection strings look like open a linked table in design view and open the Properties window.
    This link should also help:
    https://www.connectionstrings.com/access/

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  8. #8
    lmarconi is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Sep 2020
    Location
    Muscat
    Posts
    74
    Quote Originally Posted by Gicu View Post
    Here is how I used to do that, no need to remove the tables when you send back the updated FE; have a settings table in your FE where you save the connection string for the live BE on the client site and the one for your development BE. Same table has a yes\no field to initiate the change and a "target" field (LIVE or TEST).
    You just need to call the custom VBA function from the very first line of the AutoExec macro (if you have a form set as opening form remove that and do it in the AutoExec after you re-link because if the form is bound it will interfere with the re-linking).

    See the attached sample for all objects required.

    Cheers,
    Thank you all for kindly suggestion.
    First i would like to clarify that the User FE database don't use any Drive but the network path and i did exactly to avoid problem of drive letter as mentioned by Micron.

    I used the Gicu's script and looks like the source doesn't change so i would like to understand if i did some mistake. In the setting table i use:
    ConnetcionStringLive = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\\musnas04\cpd_projects\CTO_OR\05- M&I\05-M&I Support\QAQC Supportive Documents\_QAQC Tool\Database\BE\ARDC-BE-R1.mdb;" (which is the user BE database in their network and which is the one i need to reconnect)
    ConnectionStringTest = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Scratch\C Data\Desktop\QA -QC tools\Main DB\R5.8\be\ARDC-BE-R1.mdb;Persist Security Info=False;" (which is my BE database in my local disk)
    ConnectTo = "Live"
    ChangeSource = "True"

    Then i use the Macro Autoexec with the function "vcChangeSource()"
    When the autoexec start, it seams change the source (system also give message that source is changed) but the tables are linked always to my BE "ConnectionStringTest".

    Where i did mistake?
    Cheers,

  9. #9
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,112
    Let me have a look and I'll get back to you, need to check the connection string formats.

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  10. #10
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,112
    Please try these connection strings:
    Live:
    ;DATABASE=\\musnas04\cpd_projects\CTO_OR\05- M&I\05-M&I Support\QAQC Supportive Documents\_QAQC Tool\Database\BE\ARDC-BE-R1.mdb;TABLE=

    Test:
    ;DATABASE= C:\Scratch\C Data\Desktop\QA -QC tools\Main DB\R5.8\be\ARDC-BE-R1.mdb;TABLE=

    And replace the vcLinkTableDefs() function with this updated one (it concatenates the source table name to the strings in the settings table):

    Code:
    Public Function vcLinkTableDefs()
    Dim dbs As DAO.Database
    Dim tdf As DAO.TableDef
    Dim strNewConnectionString As String, sSourceTable As String
    
    
    On Error Resume Next
    
    
     strNewConnectionString = IIf(DLookup("ConnectTo", "tblSettings") = "Test", DLookup("[ConnectionStringTest]", "[tblSettings]"), DLookup("[ConnectionStringLive]", "[tblSettings]"))
      Set dbs = CurrentDb()
    
    
      ' Loop through TableDefs collection, only processing
      ' the table if it already has a Connection property.
      ' (all other tables are local ... not linked)
    
    
      For Each tdf In dbs.TableDefs
    
    
        If tdf.Connect <> "" Then
            sSourceTable = tdf.SourceTableName
            If tdf.Connect <> strNewConnectionString Then
                tdf.Connect = strNewConnectionString & sSourceTable
                tdf.RefreshLink
            End If
        End If
      Next
     
     Set tdf = Nothing
     Set dbs = Nothing
    End Function
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  11. #11
    lmarconi is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Sep 2020
    Location
    Muscat
    Posts
    74
    Good morning and thanks you first of all.
    It works now for the "Live" string, so it change if i have Test BE to Live BE but not work to the contrary, so if i have "Live" BE and want to change to "Test", string not change.
    I used the string you suggested and the new function.
    Any further suggestion? This could be not a big issue because the user need to use the "Live" so i could link the "Test" manually in my PC but, as you did so good function, it is interesting to know why it not work for "Test".
    Cheers,

  12. #12
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,112
    Can you try an alternate path in your C:\ drive (maybe with no spaces in the path) ?

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  13. #13
    lmarconi is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Sep 2020
    Location
    Muscat
    Posts
    74
    I tried: ;DATABASE= C:\Scratch\be\ARDC-BE-R1.mdb;TABLE=
    But is the same, don't change.
    Cheers,

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

Similar Threads

  1. Replies: 4
    Last Post: 11-03-2020, 10:32 AM
  2. Replies: 3
    Last Post: 11-15-2013, 03:15 PM
  3. Replies: 2
    Last Post: 09-09-2012, 07:45 AM
  4. Copying Linked Tables Programmatically
    By DarkWolff in forum Programming
    Replies: 1
    Last Post: 06-05-2012, 09:54 AM
  5. Programmatically Compacting Database
    By injanib in forum Access
    Replies: 15
    Last Post: 07-06-2011, 02:47 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