473,407 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Copy, Paste and Delete records from one table to another

I am new to access and VBA so please bare with me on this...I have a table I am upgrading by adding two new fields and renaming three others. Since I have several users using this database I am trying to create an update button that will copy the table from the original database into the new one and then update or copy the records from the old table to the new. I have managed to get it to work, but was wondering if there is an easier way to do it then what is listed below.

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3.  '***Is there an easier way to do this part ***
  4.  
  5.   '***Copy and Paste All Records to new table
  6.   DoCmd.OpenTable "Data Entry1", acNormal, acEdit
  7.   DoCmd.RunCommand acCmdSelectAllRecords
  8.   DoCmd.RunCommand acCmdCopy
  9.   '*************
  10.   DoCmd.OpenTable "Data Entry", acNormal, acEdit
  11.   DoCmd.RunCommand acCmdSelectAllRecords
  12.   DoCmd.RunCommand acCmdDelete
  13.   DoCmd.RunCommand acCmdPaste
  14.  
  15.   DoCmd.OpenTable "Branch #'s1", acNormal, acEdit
  16.   DoCmd.RunCommand acCmdSelectAllRecords
  17.   DoCmd.RunCommand acCmdCopy
  18.   '*************
  19.   DoCmd.OpenTable "Branch #'s", acNormal, acEdit
  20.   DoCmd.RunCommand acCmdSelectAllRecords
  21.   DoCmd.RunCommand acCmdDelete
  22.   DoCmd.RunCommand acCmdPaste
  23.  
  24.   DoCmd.OpenTable "Setup1", acNormal, acEdit
  25.   DoCmd.RunCommand acCmdSelectAllRecords
  26.   DoCmd.RunCommand acCmdCopy
  27.   '*************
  28.   DoCmd.OpenTable "Setup", acNormal, acEdit
  29.   DoCmd.RunCommand acCmdSelectAllRecords
  30.   DoCmd.RunCommand acCmdDelete
  31.   DoCmd.RunCommand acCmdPaste
  32.  
  33.  
  34.   '***Close Tables***
  35.   DoCmd.Close acTable, "Data Entry1", acSaveNo
  36.   DoCmd.Close acTable, "Data Entry", acSaveYes
  37.   DoCmd.Close acTable, "Branch #'s1", acSaveNo
  38.   DoCmd.Close acTable, "Branch #'s", acSaveYes
  39.   DoCmd.Close acTable, "Setup1", acSaveNo
  40.   DoCmd.Close acTable, "Setup", acSaveYes
  41.  
  42.   '***Deletes Table After Imported***
  43.   DoCmd.DeleteObject acTable, "Data Entry1"
  44.   DoCmd.DeleteObject acTable, "Branch #'s1"
  45.   DoCmd.DeleteObject acTable, "Setup1"
  46.  
  47.  
Jun 6 '10 #1

✓ answered by ADezii

@timleonard
Expand|Select|Wrap|Line Numbers
  1. 'DELETE all the Records from the Data Entry Table
  2. CurrentDb.Execute "DELETE * FROM [Data Entry]", dbFailOnError
  3.  
  4. 'Execute an APPEND Query that will dump the Records from [Data Entry1]
  5. 'into the [Data Entry] Table
  6. DoCmd.SetWarnings False
  7.   DoCmd.OpenQuery "qApdDataEntry1ToDataEntry"
  8. DoCmd.SetWarnings True

7 7673
ADezii
8,834 Expert 8TB
@timleonard
Expand|Select|Wrap|Line Numbers
  1. On Error Resume Next
  2. CurrentDb.TableDefs.Delete "Data Entry"
  3.  
  4. DoCmd.CopyObject , "Data Entry", acTable, "Data Entry1"
Jun 7 '10 #2
@ADezii
Thanks for the fast reply...

I tried the code above, line 2 states the database engine could not lock table because it is in use and line 4 states that "Data Entry" has relationships and cannot be deleted. I should have mentioned that the table "Data Entry" has relationships. Is there a possibility to do this without deleting the table?
Jun 7 '10 #3
ADezii
8,834 Expert 8TB
@timleonard
Under these conditions, must more information must be known concerning tyhe Data Entry Table, as in:
  1. What Relationships are this Table involved in?
  2. Is Referential Integrity enforced on the above Relationships?
  3. Are cascading Deletes enforced on the above Relationships?
Jun 7 '10 #4
@ADezii
Answers to above.
1. The "Data Entry" table shares relationships with two other tables, "Setup" and "Branch #'s"

2. I don't believe I have any Referential Integrity enforced.

3. There is a delete and an update query tied to the table


Hope this is what you were asking, and thank you for the help
Jun 7 '10 #5
ADezii
8,834 Expert 8TB
@timleonard
Expand|Select|Wrap|Line Numbers
  1. 'DELETE all the Records from the Data Entry Table
  2. CurrentDb.Execute "DELETE * FROM [Data Entry]", dbFailOnError
  3.  
  4. 'Execute an APPEND Query that will dump the Records from [Data Entry1]
  5. 'into the [Data Entry] Table
  6. DoCmd.SetWarnings False
  7.   DoCmd.OpenQuery "qApdDataEntry1ToDataEntry"
  8. DoCmd.SetWarnings True
Jun 7 '10 #6
@ADezii
This seems to work...Thanks again for your help
Jun 8 '10 #7
ADezii
8,834 Expert 8TB
@timleonard
You are quite welcome.
Jun 8 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Sean Howard | last post by:
Dear All, As is my want I need to do something in Access that seems simple but cannot fathom out. I have main form with two subforms, both datasheets with an almost identical table structure....
6
by: Sven Pran | last post by:
Probably the answer is there just in front of me only awaiting me to discover it, but: 1: I want to build a query that returns all records in one table for which there is no successful "join"...
4
by: Legendary Pansy | last post by:
I was checking out the 101 C# Samples, specifically Windows Forms - Use the Clipboard. I took a look at the code for a while, and I understand what the program is doing with the cut, copy, pasting...
1
by: Kuups | last post by:
Hi! I have a question is there any way of disabling the Copy, Paste, Delete ? of a Windows Control Tex Box Right Click Property during runtime ? Thanks!
7
by: lgbjr | last post by:
Hello All, I¡¯m using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard was easy. But pasting an image from the clipboard...
0
by: Brad | last post by:
Thanks for taking the time to read my question. I have a split DB and I want to be able to delete the old table, copy an existing table that is in the back end, rename it, and then make sure all...
5
by: Kaur | last post by:
Hi, I have been successful copying a vba code from one of your posts on how to copy and paste a record by declaring the desired fields that needs to be copied in form's declaration and creating two...
9
by: jbrumbau | last post by:
Hi all, I'm having difficulty catching error 8511, which states: "Records that Microsoft Office Access was unable to paste have been inserted into a new table called 'Paste Errors' In the...
0
by: Ruth Barn | last post by:
When I use a standard append query; 50 of the 10 'pass', 40 do not append due to validation rules. But the 10 are still not actually added to the TASK table after the append is run and they do not...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.