Migrate a table in the database to another database (1 Viewer)

azhar2006

Registered User.
Local time
Today, 02:17
Joined
Feb 8, 2012
Messages
202
Hello guys .
I am migrating a table in the database to another database in partition(D) through an append query. And use a button to run this query based on the event below on click. What I want is when I run the append query through the button, a message appears saying that I have appended or updated data, and the number of records is such a record. How to do it . Thanks to all .
Code:
On Error Resume Next

    DoCmd.Hourglass True       
    DoCmd.SetWarnings False
    DoCmd.OpenQuery "QueryAppend", acViewNormal, acEdit
    DoCmd.Hourglass False
    DoCmd.SetWarnings True
 

theDBguy

I’m here to help
Staff member
Local time
Today, 02:17
Joined
Oct 29, 2018
Messages
21,467
Have you tried it this way?
Code:
With CurrentDb
    .Execute "QueryAppend", dbFailOnError
    MsgBox "Appended " & .RecordsAffected & " records.", vbInformation, "Info"
End With
 

azhar2006

Registered User.
Local time
Today, 02:17
Joined
Feb 8, 2012
Messages
202
Have you tried it this way?
Code:
With CurrentDb
    .Execute "QueryAppend", dbFailOnError
    MsgBox "Appended " & .RecordsAffected & " records.", vbInformation, "Info"
End With
Thank you dear DBG ..yes, I have now tried it and it shows me the number of records is zero
 

theDBguy

I’m here to help
Staff member
Local time
Today, 02:17
Joined
Oct 29, 2018
Messages
21,467
Thank you dear DBG ..yes, I have now tried it and it shows me the number of records is zero
Is that correct or no? If not, try running the query from the nav pane and see how many records it's suppose to say.
 

azhar2006

Registered User.
Local time
Today, 02:17
Joined
Feb 8, 2012
Messages
202
Is that correct or no? If not, try running the query from the nav pane and see how many records it's suppose to say.
Show me this message. After pressing yes, another message appears. But when removing the password from the database, this message appeared
 

Attachments

  • 1.JPG
    1.JPG
    29.4 KB · Views: 203
  • 2.JPG
    2.JPG
    14.8 KB · Views: 206
  • 3.JPG
    3.JPG
    22.9 KB · Views: 202
Last edited:

theDBguy

I’m here to help
Staff member
Local time
Today, 02:17
Joined
Oct 29, 2018
Messages
21,467
Show me this message. After pressing yes, another message appears. But when removing the password from the database, this message appeared
So, if you remove the password from the database and run the code I gave you earlier, does it say the same number of records?
 

azhar2006

Registered User.
Local time
Today, 02:17
Joined
Feb 8, 2012
Messages
202
So, if you remove the password from the database and run the code I gave you earlier, does it say the same number of records?
keeps giving zero
Code:
On Error Resume Next


DoCmd.Hourglass True
      
        DoCmd.SetWarnings False
With CurrentDb
   .Execute "QueryAppend", dbFailOnError
    MsgBox "Appended " & .RecordsAffected & " records.", vbInformation, "Info"
            
End With

    DoCmd.Hourglass False
    
        DoCmd.SetWarnings True
 

theDBguy

I’m here to help
Staff member
Local time
Today, 02:17
Joined
Oct 29, 2018
Messages
21,467
keeps giving zero
Code:
On Error Resume Next


DoCmd.Hourglass True
     
        DoCmd.SetWarnings False
With CurrentDb
   .Execute "QueryAppend", dbFailOnError
    MsgBox "Appended " & .RecordsAffected & " records.", vbInformation, "Info"
           
End With

    DoCmd.Hourglass False
   
        DoCmd.SetWarnings True
Can you post the SQL statement for QueryAppend?
 

azhar2006

Registered User.
Local time
Today, 02:17
Joined
Feb 8, 2012
Messages
202
Can you post the SQL statement for QueryAppend?
The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. (Error 3022)

You tried to duplicate a value in a field that is the underlying table's primary key or an index that does not allow duplicates.

The message includes the following instruction: Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to permit duplicate entries, and try again.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 02:17
Joined
Oct 29, 2018
Messages
21,467
The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. (Error 3022)

You tried to duplicate a value in a field that is the underlying table's primary key or an index that does not allow duplicates.

The message includes the following instruction: Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to permit duplicate entries, and try again.
You should get that same error message whether you use code or manually run the APPEND query. Which means, you'll have to fix the query to exclude the index violations or fix the data.
 

azhar2006

Registered User.
Local time
Today, 02:17
Joined
Feb 8, 2012
Messages
202
You should get that same error message whether you use code or manually run the APPEND query. Which means, you'll have to fix the query to exclude the index violations or fix the data.
Thank you my dear friend DBG you saved me. It was the (On Error Resume Next) line that prevented me from knowing where the problem lay. Thanks a lot for the help. Your code worked well.:p:p:giggle::giggle:
 

Attachments

  • 111.JPG
    111.JPG
    15.5 KB · Views: 204

Pat Hartman

Super Moderator
Staff member
Local time
Today, 05:17
Joined
Feb 19, 2002
Messages
43,263
What I want is when I run the append query through the button, a message appears saying that I have appended or updated data, and the number of records is such a record.

You turned off Warnings so you are not getting the message you expect. I prefer the .execute method myself but try removing the commands to turn off warnings and see if your original code works.
 

azhar2006

Registered User.
Local time
Today, 02:17
Joined
Feb 8, 2012
Messages
202
You turned off Warnings so you are not getting the message you expect. I prefer the .execute method myself but try removing the commands to turn off warnings and see if your original code works.
Your words are always accurate. We are beginners. We go to turn off the warning messages haha and we know there's a lot of trouble behind it, a bit like that of an old car.:giggle:
 

theDBguy

I’m here to help
Staff member
Local time
Today, 02:17
Joined
Oct 29, 2018
Messages
21,467
Do I delete the ID number field from the query? I sent you a sentence SQL have you seen it?
If ID is the primary key in the destination table, then check your data and make sure you're not trying to add duplicate ID values. If so, then yes, try taking them out.
 

Users who are viewing this thread

Top Bottom