Avatar of ca1358
ca1358
 asked on

DoCmd.CopyObject and Retain Primary Key

Is there a way to use "DoCmd.CopyObject " and the table retain the Primary Key.
DoCmd.CopyObject "\\xxxxx\xxxxx\xxxxx\xxxx\xxxxx", "Backup_Backup" & sNow, acTable, "Backup_Backup"

Open in new window

Visual Basic ClassicMicrosoft Access

Avatar of undefined
Last Comment
ca1358

8/22/2022 - Mon
Scott McDaniel (EE MVE )

Are you moving this in from another database? If so, then use the TransferDatabase method instead:

DoCmd.TransferDatabase acImport, ,"C:\MyFolder\MyDatabase.mdb", acTable,  "SourceTableName", "Destination TableName"

TransferDatabase method:
http://msdn.microsoft.com/en-us/library/aa220761%28v=office.11%29.aspx
ca1358

ASKER
I thank you kindly for your time.

I am Exporting the table to another database.
I am getting a runtime error 2507.
The type isn’t installed database type or doesn’t support the operation you chose.

Also I need to include the date and time as part of the Destination TableName.

I have included more of the code.  

Thank you again.
Option Explicit
Private Sub Form_Open(Cancel As Integer)
Me.TimerInterval = 60000
End Sub

Private Sub Form_Timer()
DoCmd.RunMacro "macro1"
Me.Requery
Me.TimeRecord.Requery
Forms!form2!Form3.Requery

Dim ILSPBackup As String
Dim sNow As Variant
sNow = Format(Date, " yyyymmdd") & "_" & Format(Time, "hhnn")

Dim strDestinationMDB As String
Dim dbsData As DAO.Database
strDestinationMDB = XXXXXXXX\XXXXXXX\XXXXXX\MyDatabase.mdb"
Set dbsData = DBEngine.OpenDatabase(strDestinationMDB, _
False, False, ";pwd=XXXXXXX")
DoCmd.SetWarnings False
DoCmd.TransferDatabase acExport, ,"C:\MyFolder\MyDatabase.mdb", acTable,  "SourceTableName", "Destination TableName"
End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Scott McDaniel (EE MVE )

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ca1358

ASKER
Thank you
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy