1

I am trying to change the linked table address from an Access file "Hey.accdb" using VBA coding from an Excel file.

I've coded the script below in my Excel file and it prompts the error "Object required" when I run it. Can someone please help me with this problem. I've been staring at it for too long. Thanks.

Sub RunMacroinAccesswithPara2()

Set Db = CreateObject("Access.Application")
        Db.OpenCurrentDatabase "D:\Database1\Hey.accdb"
        Db.Visible = True
        Db.AutomationSecurity = msoAutomationSecurityLow

    DoCmd.TransferDatabase TransferType:=acLink, _
        DatabaseType:="Microsoft Access", _
        DatabaseName:="V:\Reporting\Quarterly\2018Q2\JP\Data\04\Database\Valuation_Database.mdb", _
        ObjectType:=acTable, _
        Source:="Valuation_Database_Adjusted", _
        Destination:="Valuation_Database_Adjusted"

End Sub
0

1 Answer 1

1

DoCmd belongs to the Access application object.

So use

Db.DoCmd.TransferDatabase ' etc.

Edit

To update the link, you need the TableDef object, set its .Connect property and run .RefreshLink.

See Linked table ms access 2010 change connection string

Sign up to request clarification or add additional context in comments.

1 Comment

Hi Andre! This works. However, it creates a duplicate table. Is there anyway I could just update the existing table's linkage (without using delete table then transferdatabase)?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.