Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Database (http://www.go4expert.com/forums/database-forum/)
-   -   relink to relative path txt data file (http://www.go4expert.com/forums/relink-relative-path-txt-data-file-t13066/)

tobynegus 19Aug2008 21:25

relink to relative path txt data file
 
I have a access 2000 database (currently running jet3.6) that has linked TXT and CSV files
I need to be able to move the location of the database often, the linked data will always be in the same place /Rawdata/ relative to the MDB file
is there anyway this can be automated to relink into the current location?


Thank you for your attention

Toby :pleased:

skp819 10Dec2008 16:18

Re: relink to relative path txt data file
 
  1. Create a Table named tblTablesToLink with the following 2 Fields:
    • FileName {TEXT} - Name only of Text File, e.g. March Sales.txt
    • TableName {TEXT} - Linked Name as you would like it to appear in DB Window
  2. Populate this Table with all the Names of the Text Files you would like to dynamically Link, as well as the Linked Names as you would like them to appear in the DB Window.
  3. Make sure to Copy these Files to the RawData Directory one level under the Directory where the Database resides.
  4. Run this code:
    Expand|Select|Wrap|Line Numbers
    1. On Error Resume Next
    2. Dim MyDB As DAO.Database
    3. Dim rstFilesToLink As DAO.Recordset
    4. Dim strPathToFiles As String
    5. strPathToFiles = CurrentProject.Path & "\RawData\"
    6. Set MyDB = CurrentDb
    7. Set rstFilesToLink = MyDB.OpenRecordset("tblTablesToLink", dbOpenForwardOnly)
    8. With rstFilesToLink
    9. Do While Not .EOF
    10. 'DELETE each existing Link, then RECREATE it!
    11. CurrentDb.TableDefs.Delete ![TableName]
    12. DoCmd.TransferText acLinkDelim, , ![TableName], strPathToFiles & ![FileName], False
    13. .MoveNext
    14. Loop
    15. End With
    16. rstFilesToLink.Close
    17. Set rstFilesToLink = Nothing




All times are GMT +5.5. The time now is 16:04.