Link Tables in VB

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dan2kx
    Contributor
    • Oct 2007
    • 365

    #16
    NeoPa (or anyone else), i need your help with this again,
    I had it working before but want to use it in a new database here is my code:

    Code:
    Function TableReMap(tbl As String, Path As String)
    Dim DB As DAO.Database, tblDef As DAO.TableDef
        Set DB = CurrentDb
        Set tblDef = DB.CreateTableDef(tbl)
        tblDef.Connect = ";Database=" & Path
        tblDef.RefreshLink
    It errors at the refreshlink line and says "invalid operation" (3219)

    Any ideas? (all the variables are set correctly (AFAIK)

    Dan

    Comment

    • Dan2kx
      Contributor
      • Oct 2007
      • 365

      #17
      False alarm, i found my original code
      Code:
      Function TableReMap(tbl As String, Path As String)
      Dim tdf As DAO.TableDef, strPath As String
          strPath = ";Database=" & Path
          For Each tdf In CurrentDb.TableDefs
              If tdf.Name = tbl Then
                  If strPath <> tdf.Connect Then
                      tdf.Connect = strPath
                      tdf.RefreshLink
                  End If
              End If
          Next
      End Function
      not quite sure how that differs (apart from the loop) but that access for ya huh (or just me i dont know)

      Dan

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32666

        #18
        Your code for post #16 is actually trying to create a new TableDef rather than amend an existing one (See line #4 particularly).

        Comment

        • FishVal
          Recognized Expert Specialist
          • Jun 2007
          • 2656

          #19
          Originally posted by NeoPa
          Your code for post #16 is actually trying to create a new TableDef rather than amend an existing one (See line #4 particularly).
          And TableDef object returned by DAO.Database.Cr eateTableDef method has to be appended to TableDefs collection via TableDefs.Appen d method to become an existing Access table.

          Comment

          • Dan2kx
            Contributor
            • Oct 2007
            • 365

            #20
            Ok thanks fellas, i did try some other fiddles before i got to that code but they didnt seem to work either.

            the trouble i had was trying to set a string value as a tabledef eg

            Code:
            set tbl = "TableName"
            how would you do that (for future reference)?

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32666

              #21
              If you look at post #15 then line #9 illustrates this (as a With version rather than a Set mind). For that you would use something like :
              Code:
              Set tbl = CurrentDB.TableDefs("TableName")

              Comment

              Working...