Results 1 to 3 of 3
  1. #1
    steve7800 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    41

    How to use the CopyObject method

    I’m trying to understand how to use the CopyObject method. I have successfully used this method to copy a table and give it a new name in the same database. But I need to copy a table from a different database into the database I am working with -- that's where I stumble.

    When working in Animals.accdb, this line of code in the load event of a form works as expected, making a copy of tblDomesticated and renaming it:

    Code:
    DoCmd.CopyObject , "tblDomesticatedCopy", acTable, “tblDomesticated”
    When working from another database, the same line of code in a form load event produces run-time error 7874: Microsoft Access cant’ find the object ‘tblDomesticated’. Not surprising.

    When working in a different database, I tried this line of code to copy a table from Animals.accdb, but I get run-time error 2465: Microsoft Access can't find the field '|1' referred to in your expression. An internet search turns up a lot of users with this error but no clear explanation of what it is.

    Code:
    DoCmd.CopyObject , "tblDomesticatedCopy", acTable, [C:\Stuff\Animals.accdb].[tblDomesticated]
    So one question I’d appreciate some help with is does the CopyObject method support copying an object (a table in this case) from one Access database to another? If so, how does one reference the object in the “other” database?

    Thanks.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,735
    I think can CopyObject TO a database but not pull from. Use Docmd.TransferDatabase instead?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    steve7800 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    41
    Worked first time. Thank you.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 07-26-2017, 08:14 AM
  2. Replies: 6
    Last Post: 06-25-2016, 02:56 PM
  3. Replies: 6
    Last Post: 07-04-2015, 06:10 PM
  4. What can be the best method?
    By cap.zadi in forum Database Design
    Replies: 2
    Last Post: 03-04-2013, 10:26 PM
  5. Replies: 4
    Last Post: 11-05-2010, 04:56 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums