Share via

Update linked table details using VBA

Anonymous
2010-07-09T06:12:36+00:00

I want to be able to update the location of an Excel worksheet linked to a database table by entering the new path in a form's textbox and then excuting whatever VBA code is necessary to update the link (I don't want users having to access the Linked Table Manager and other Menus etc.) I know how to provide the means for Users to use a dialog box to select the file path, its the VBA code needed to then amend the location as you would normally do in the Linked Table Manager that I need. Is this possible please?

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2010-07-09T08:34:58+00:00

Hi grimwadec,

There's no such function as ELookup(). In Access, it's DLookup().

Also, since all you're doing is changing the path to the file, you don't need to specify the worksheet, since you had to specify it when you first connected. Just set the Connect property to the path and filename.

"grimwadec" wrote in message news:*** Email address is removed for privacy *** .com...

OK so here's the code I tried:

Dim tdf As DAO.TableDef, ExcelPath As String

ExcelPath = ELookup("ExcelPath", "tblSundries", , "ExcelPath DESC")

Set tdf = DBEngine(0)(0).TableDefs("tblClubsSrc")

tdf.Connect = Left(tdf.Connect, InStr(1, tdf.Connect, "DATABASE=") + 8) & (ExcelPath & "\Clubs$")tdf.RefreshLink

Set tdf = Nothing

The worksheet in EntrySheet.xls is called "Clubs". I get Run-time error 3044 message*"C:\TrialFolder\EntrySheet.xls\Clubs$"* is not a valid path but I note that the preceding italicised text matches what I achieve using the Linked Table Manager which reflectstblClubsSrc  (C:\TrialFolder\EntrySheet.xls\Clubs$)

so I presume there is something wrong with the way I have put the ExcelPath and the Worksheet name together. Perhaps if I had tried to solve a problem I previously had using GetExcel and Detect Excel I might have been able to solve this issue! Help please!

 


Regards, Graham R Seach Microsoft Access MVP Sydney, Australia

Was this answer helpful?

0 comments No comments

6 additional answers

Sort by: Most helpful
  1. Anonymous
    2010-07-09T06:23:56+00:00

    Hi grimwadec,

    The code is as follows:

    Dim tdf As DAO.TableDef

    Set tdf = DBEngine(0)(0).TableDefs("mytablename")

    tdf.Connect = left(tdf.Connect,instr(1,tdf.Connect,"DATABASE=")+8) & strMyNewPath

    tdf.RefreshLink

    Set tdf = Nothing

    "grimwadec" wrote in message news:*** Email address is removed for privacy *** .com...

    I want to be able to update the location of an Excel worksheet linked to a database table by entering the new path in a form's textbox and then excuting whatever VBA code is necessary to update the link (I don't want users having to access the Linked Table Manager and other Menus etc.) I know how to provide the means for Users to use a dialog box to select the file path, its the VBA code needed to then amend the location as you would normally do in the Linked Table Manager that I need. Is this possible please?


    Regards, Graham R Seach Microsoft Access MVP Sydney, Australia

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  2. Anonymous
    2010-07-09T06:57:03+00:00

    If you still don't feel confident with loops or DAO, or whatever, try asking a new question. That's what we're here for.

    "grimwadec" wrote in message news:*** Email address is removed for privacy *** .com...

    Thanks Graham...will try it and let you know (that it works presumably) ...I asked a question some time ago re Loops stating I knew so little about them and one of your fellow MVP's told me that my shortcoming was in DAO' s not loops...I tried to pick up some knowledge of them but a good source of learning about them eludes me.


    Regards, Graham R Seach Microsoft Access MVP Sydney, Australia

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2010-07-09T06:54:31+00:00

    Thanks Graham...will try it and let you know (that it works presumably) ...I asked a question some time ago re Loops stating I knew so little about them and one of your fellow MVP's told me that my shortcoming was in DAO' s not loops...I tried to pick up some knowledge of them but a good source of learning about them eludes me.

    Was this answer helpful?

    0 comments No comments
  4. Tom van Stiphout 40,211 Reputation points MVP Volunteer Moderator
    2010-07-09T06:17:57+00:00

    You need to make two calls on the tabledef object: set the Connect property, and call the RefreshLink method.


    -Tom. Microsoft Access MVP

    Was this answer helpful?

    0 comments No comments