Results 1 to 8 of 8

Thread: Refreshing Links for Linked Tables [RESOLVED]

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2004
    Location
    Jakarta, Indonesia
    Posts
    818

    Resolved Refreshing Links for Linked Tables [RESOLVED]

    can anyone have an idea how to do this?
    i used Access

    thanks
    Last edited by erickwidya; Nov 10th, 2004 at 10:46 PM.

    1st NF - a table should not contain repeating groups.
    2nd NF - any fields that do not depend fully on the primary key should be moved to another table.
    3rd NF - there should be no dependency between non key fields in same table.
    - E. Petroutsos -


    eRiCk

    A collection of "Laku-abis" Ebook, Permanent Residence

    Access Reserved Words, a Classic Form Bug, Access Limitation, Know run Process and the Lock they hold in, Logging User Activity in MSSQL,
    Kill Database Processes

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343
    What exactly do you want to do...?
    And with what? Access forms to tables or vb to access? or vb to access to access?
    Dao or AdoX?


    Vince

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2004
    Location
    Jakarta, Indonesia
    Posts
    818
    sorry for incomplete info

    as u see..i can make a link tables using Access..and with Access too i can make the link table to set new link location if the backend dbase is remove to other location..

    what i want is to do it in vb via ADOX i think :0
    first it will see if the link location is not moved..if it move..it'll prompt the user to set new location..and use that new location to refresh the link..

    i got the code from MSDN..but it's not working..
    VB Code:
    1. Sub RefreshLinks(strDBLinkFrom As String, _
    2.      strDBLinkSource As String)
    3. Dim catDB As ADOX.Catalog    
    4. Dim tblLink As ADOX.Table      
    5. Set catDB = New ADOX.Catalog     ' Open a catalog on the database in which to refresh links.    
    6. catDB.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _        
    7. "Data Source=" & strDBLinkFrom      
    8. For Each tblLink In catDB.Tables        ' Check to make sure table is a linked table.        
    9.   If tblLink.Type = "LINK" Then          
    10.     tblLink.Properties("Jet OLEDB:Link Datasource") = strDBLinkSource
    11.     [b]tblLink.Properties("Jet OLEDB:Create Link") = True[/b]
    12.   End If    
    13. Next      
    14.  
    15. set catDB = Nothing  
    16. End Sub

    the error said..'multistep line error.. '' at the bold part
    thanks
    Last edited by erickwidya; Nov 8th, 2004 at 09:48 PM.

    1st NF - a table should not contain repeating groups.
    2nd NF - any fields that do not depend fully on the primary key should be moved to another table.
    3rd NF - there should be no dependency between non key fields in same table.
    - E. Petroutsos -


    eRiCk

    A collection of "Laku-abis" Ebook, Permanent Residence

    Access Reserved Words, a Classic Form Bug, Access Limitation, Know run Process and the Lock they hold in, Logging User Activity in MSSQL,
    Kill Database Processes

  4. #4
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343
    VB Code:
    1. Public Sub ADOConnectTablesFromMDB(ByVal strMDBPath As String, Optional strPassword, Optional blnReplaceTables, Optional strMDWPath)
    2. '---- Relinks tables from another db to this one (not system tables)
    3.  
    4. '---- Requires
    5. '----   MDB Path
    6. '----   Password (Optional) if mdb is passworded
    7. '----   Replace Table (Optional) replaces the table if it exists already
    8. '----   - otherwise, add table with an incrementing number appended to title
    9. '----   MDW Path (Optional) if mdb is using a different system file
    10.    
    11. '---- information from :
    12. ' from  : [url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnofftalk/html/office10052000.asp[/url]
    13.    
    14.     Dim adoxCatDB As ADOX.Catalog, adoxCatDBOut As ADOX.Catalog
    15.     Dim adoxTbl As ADOX.Table, adoxNewTable As ADOX.Table
    16.    
    17.     Dim strConnectionString As String, strCDBTblName As String
    18.     Dim lngLoop As Long
    19.    
    20.     Dim blnDebug As Boolean, blnLeave As Boolean
    21.    
    22.     On Error Resume Next
    23.        
    24.     Set adoxCatDB = New ADOX.Catalog
    25.     Set adoxCatDBOut = New ADOX.Catalog
    26.    
    27.     adoxCatDB.ActiveConnection = CurrentProject.Connection
    28.     If blnDebug Then Debug.Print "Connecting... " & CurrentProject.Connection
    29.    
    30. '---- -- Provider string -- ----
    31. 'Provider=Microsoft.Jet.OLEDB.4.0;
    32. 'User ID=Admin;Data Source=" & strFilePath & ";
    33. 'Mode=Share Deny None;"
    34.  
    35. 'Extended Properties="";
    36. 'Jet OLEDB:System database=C:\PROGRA~1\COMMON~1\System\SYSTEM.MDW;
    37. 'Jet OLEDB:Registry Path="";
    38. 'Jet OLEDB:Database Password="";
    39. 'Jet OLEDB:Engine Type=5;
    40. 'Jet OLEDB:Database Locking Mode=1;
    41. 'Jet OLEDB:Global Partial Bulk Ops=2;
    42. 'Jet OLEDB:Global Bulk Transactions=1;
    43. 'Jet OLEDB:New Database Password="";
    44. 'Jet OLEDB:Create System Database=False;
    45. 'Jet OLEDB:Encrypt Database=False;
    46. 'Jet OLEDB:Don't Copy Locale on Compact=False;
    47. 'Jet OLEDB:Compact Without Replica Repair=False;
    48. 'Jet OLEDB:SFP=False
    49.    
    50.     strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strMDBPath & ";Mode=Share Deny None"
    51.     If Not IsMissing(strMDWPath) Then
    52.         strConnectionString = strConnectionString & "Jet OLEDB:System database=" & strMDWPath & ";"
    53.     End If
    54.    
    55.     If Not IsMissing(strPassword) Then
    56.         strConnectionString = strConnectionString & "Jet OLEDB:Database Password=" & Chr$(34) & strPassword & Chr$(34) & ";"
    57.     End If
    58.    
    59.     adoxCatDBOut.ActiveConnection = strConnectionString
    60.     Debug.Print "Connecting... " & adoxCatDBOut.ActiveConnection
    61.    
    62.     For Each adoxTbl In adoxCatDBOut.Tables
    63.    
    64.         Debug.Print adoxTbl.Type, adoxTbl.Name
    65.        
    66.         If adoxTbl.Type = "TABLE" And Not adoxTbl.Name Like "MSYS*" Then
    67.             Set adoxNewTable = New ADOX.Table
    68.             With adoxNewTable
    69.                 .Name = adoxTbl.Name
    70.                
    71.                 strCDBTblName = adoxCatDB.Tables(.Name).Name
    72.                 If Err.Number = 0 Then
    73.                     If IIf(IsMissing(blnReplaceTables), False, blnReplaceTables) Then
    74.                         adoxCatDB.Tables.Delete adoxCatDB.Tables(.Name)
    75.                     Else
    76.                         lngLoop = 1
    77.                         blnLeave = False
    78.                         Do Until blnLeave
    79.                             .Name = adoxTbl.Name & Format(lngLoop, "00")
    80.                             strCDBTblName = adoxCatDB.Tables(.Name).Name
    81.                            
    82.                             lngLoop = lngLoop + 1
    83.                             If Err.Number = 0 Then
    84.                                 blnLeave = False
    85.                             Else
    86.                                 Err.Clear
    87.                                 blnLeave = True
    88.                             End If
    89.                         Loop
    90.                     End If
    91.                 Else
    92.                     Err.Clear
    93.                 End If
    94.                
    95.                
    96.                 Set .ParentCatalog = adoxCatDB
    97.                 .Properties("Jet OLEDB:Create Link") = True
    98.                 .Properties("Jet OLEDB:Link Datasource") = strMDBPath
    99.                 .Properties("Jet OLEDB:Remote Table Name") = adoxTbl.Name
    100.             End With
    101.             adoxCatDB.Tables.Append adoxNewTable
    102.         End If
    103.     Next
    104.    
    105.     adoxCatDB.Tables.Refresh
    106.     Application.RefreshDatabaseWindow
    107.    
    108.     Set adoxCatDBOut = Nothing
    109.     Set adoxCatDB = Nothing
    110.     Set adoxTbl = Nothing
    111.    
    112. End Sub

    I don't think I updated the relink code to Ado yet, the above is just adding the tables as links (I think) to the currently open db.

    I had this in an Access db when it was Dao and had to convert to Ado. I think this works... but well um... Try n see and grab the bits you need to make yours work.

    I went for the following:
    Access FE - copied to users C: drive - holds a pointer to the shared BE
    Access BE - shared BE - holds pointers to mdbs required for sections of db plus any shared data from the sections
    Access BEs - the mdbs that hold data only for the section required

    Then had to get the tables deleted (those that were linked) and relink to the main shared db, and as you connect to the different sections, these relinked the tables to the data mdbs. Confusing, but it was an option I was exploring at the time.


    Vince

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2004
    Location
    Jakarta, Indonesia
    Posts
    818
    thanks Vince for the code..yes it is use to create link

    why u use access BE and access BEs? not quite understand from ur explanation..
    can u give axn example of what table in those two access? so i can figure it out why u do that..?

    i personally think just using two..
    one as a backend at network server..
    one is each client drive..that is link to network server..

    i can get the link part works..but i seem can't manage the refresh link method that i posted..
    it need to works coz..it must see if the link table is 'still' related to table at network server..so the app won't crash..

    the only method i could think of is to delete all the link table in client computer..then make a new link table each time..(it's not a good method..)--> seems like the one u use?

    1st NF - a table should not contain repeating groups.
    2nd NF - any fields that do not depend fully on the primary key should be moved to another table.
    3rd NF - there should be no dependency between non key fields in same table.
    - E. Petroutsos -


    eRiCk

    A collection of "Laku-abis" Ebook, Permanent Residence

    Access Reserved Words, a Classic Form Bug, Access Limitation, Know run Process and the Lock they hold in, Logging User Activity in MSSQL,
    Kill Database Processes

  6. #6
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343
    Attached is a pic for the BEs... Its only a way that apealled at the time. Might not be the best.

    The way you are describing (2 Tier) sounds fine, as to the deleting and relinking everytime for each client - should be fine, doesn't take long and you are guarenteed that the BE mdb will be attached correctly.

    Alternatively you need to check the table to see if its there (the BE) by opening a connection/recordset. If no recordset is returned, and an error is, then you'd need to delete and relink... otherwise everything would be fine.

    Your choice... You could implement both or either, then see which takes longer, or if you know that the BE folder may move, do the relink each time.

    I had to do a relink each time because the BE mdb was going to move in the future (when I wrote it) and I knew it would be moving in a month or two. So I wrote it so an admin user could reset the links without me.


    Vince

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2004
    Location
    Jakarta, Indonesia
    Posts
    818
    well it just i'm confuse coz the code i post is from MSDN (guess..M$ miss this ) and it seems the method at the code is the same like i'm doing manually at Access..so it should be pratically the same

    from MSDN..
    If the data source for a linked table is renamed or moved, you need to refresh the connection information used to establish the link. To refresh the link, update the connection string for the table by using the provider-specific Jet OLEDB:Link Datasource property, and then reestablish the link by setting the provider-specific Jet OLEDB:Create Link property to True. The following code example shows how to refresh the links for tables linked to another Access database.
    well i guess i have to stick with what i mentioned before :P until i figure it out what to do

    thanks again for the assistant Vince

    1st NF - a table should not contain repeating groups.
    2nd NF - any fields that do not depend fully on the primary key should be moved to another table.
    3rd NF - there should be no dependency between non key fields in same table.
    - E. Petroutsos -


    eRiCk

    A collection of "Laku-abis" Ebook, Permanent Residence

    Access Reserved Words, a Classic Form Bug, Access Limitation, Know run Process and the Lock they hold in, Logging User Activity in MSSQL,
    Kill Database Processes

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2004
    Location
    Jakarta, Indonesia
    Posts
    818

    well i'm managed to refresh the link

    just commented the bold part..and that part is works fine now.. (for three days trying..waalaaaaa )
    VB Code:
    1. ...
    2. For Each tblLink In catDB.Tables        ' Check to make sure table is a linked table.            
    3.   If tblLink.Type = "LINK" Then    
    4.     tblLink.Properties("Jet OLEDB:Link Datasource") = strDBLinkSource      
    5. '    [b]tblLink.Properties("Jet OLEDB:Create Link") = True[/b]
    6.    End If      
    7. Next
    8. ...

    1st NF - a table should not contain repeating groups.
    2nd NF - any fields that do not depend fully on the primary key should be moved to another table.
    3rd NF - there should be no dependency between non key fields in same table.
    - E. Petroutsos -


    eRiCk

    A collection of "Laku-abis" Ebook, Permanent Residence

    Access Reserved Words, a Classic Form Bug, Access Limitation, Know run Process and the Lock they hold in, Logging User Activity in MSSQL,
    Kill Database Processes

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width