Solved

Access 2010 - copy from one table to another

Posted on 2014-03-22
4
3,808 Views
Last Modified: 2014-03-22
When I change a value in table 1 I want to automatically copy the changed record to a new line in table 2.

How is this done?

Thx in advance.

Regards
Lars
0
Comment
Question by:LarsDyrby
  • 2
4 Comments
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points
ID: 39947293
2010 includes the new Data Macro that can help to do this, but if you're always doing this through a Form, then you could use straight SQL and VBA.

In the Form's BeforeUpdate event, do this:

Currentdb.Execute "INSERT INTO YourTable (Col1, Col2, Col3) VALUES(" & Me.tx1 & "," & Me.tx2 & "," & Me.tx3 & ")"

If any of those are Text fields, you'll have to surround them with single or double quotes as I did below for tx1. It here are any Date fields, you'd use the hash mark (#), as I did below for tx3:

Currentdb.Execute "INSERT INTO YourTable (Col1, Col2, Col3) VALUES('" & Me.tx1 & "'," & Me.tx2 & ",#" & Me.tx3 & "#)"

If you'd prefer to use Data Macros, see this article:

http://www.databasejournal.com/features/msaccess/article.php/3905921/Leveraging-Data-Macro-in-Microsoft-Access-2010.htm
0
 

Author Closing Comment

by:LarsDyrby
ID: 39947372
I used the solution in the Data Macro link in the bottom of the answer.
Worked beautifully.

Thx Scott

Regards
Lars
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 39947373
Just a side question here, why?

Unless the 2nd table is some form of audit trail, I question the necessity (or the logic in) of storing duplicate information in multiple tables.
0
 

Author Comment

by:LarsDyrby
ID: 39947751
...which exactly is the purpose of table 2.

Regards
Lars
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now