• Updating Linked Table Source Using VBA (97)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Updating Linked Table Source Using VBA (97)

    Author
    Topic
    #407043

    I have a linked table called “enable” and I would like to change the source of the data using VBA.

    I have the following 2 lines in a function:

    CurrentDb.TableDefs(“enable”).Connect = “DATABASE = j:groupsvaluationewmethfpvafpen0406.mdb”
    CurrentDb.TableDefs(“enable”).RefreshLink

    The 0406 is the year and month of my datafile. The table is currently linked to the 0405 datafile. When I execute this function, it seems to have no effect. The link stays as 0405. What am I doing wrong?

    Thanks.

    Viewing 1 reply thread
    Author
    Replies
    • #848389

      This is because CurrentDb creates a new object each time you use it, so the second instance is not connected to the first one. Instead, use an object of type DAO.Database that you set to CurrentDb. That way, its gets created only once:

      Dim dbs As DAO.Database
      Set dbs = CurrentDb
      With dbs.TableDefs(“enable”)
      .Connect = “;DATABASE=j:groupsvaluationewmethfpvafpen0406.mdb”
      .RefreshLink
      End With
      Set dbs = Nothing

      • #848420

        Thanks so much, Hans. This works perfectly now. I suspect that this has been my core problem causing all of my posts in the Access board recently. I assumed that CurrentDB behaved just like ActiveWorkbook in Excel VBA.

      • #848421

        Thanks so much, Hans. This works perfectly now. I suspect that this has been my core problem causing all of my posts in the Access board recently. I assumed that CurrentDB behaved just like ActiveWorkbook in Excel VBA.

    • #848390

      This is because CurrentDb creates a new object each time you use it, so the second instance is not connected to the first one. Instead, use an object of type DAO.Database that you set to CurrentDb. That way, its gets created only once:

      Dim dbs As DAO.Database
      Set dbs = CurrentDb
      With dbs.TableDefs(“enable”)
      .Connect = “;DATABASE=j:groupsvaluationewmethfpvafpen0406.mdb”
      .RefreshLink
      End With
      Set dbs = Nothing

    Viewing 1 reply thread
    Reply To: Updating Linked Table Source Using VBA (97)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: