Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Access update one tbl with contents from anohter tbl

Posted on 2014-02-28
6
Medium Priority
?
286 Views
Last Modified: 2014-02-28
I have a table called "Source". The source table has three fields called A, B, and C. Fields A and B are primary keys. Field C has amounts that I want to copy to my "target" table based on matching the two primary keys. The target table also has fields A, B, and C. How do I do this?
conernesto
0
Comment
Question by:Conernesto
  • 3
  • 3
6 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 39895915
Try running an update query:

UPDATE Source, Target
SET Target.c = Source.c
WHERE Source.a = Target.a AND source.B = Target.b

Open in new window

0
 

Author Comment

by:Conernesto
ID: 39895962
I am not sure how to do this.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 39895999
1.  Open a new query
2.  Close the "Show Table" dialog without selecting any tables.
3.  Right click the query window and select "SQL View"
4.  Copy/paste the SQL I gave you into the SQL Window
5.  Try running it by clicking the Exclamation Point above the query window OR by right-clicking the query window and selecting Datasheet View.
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 

Author Comment

by:Conernesto
ID: 39896162
It worked. How can I put the above code in a command button?
0
 
LVL 61

Accepted Solution

by:
mbizup earned 2000 total points
ID: 39896269
You can embed it in VBA in the click event of your command button like this:

Sub YourCommandButtonName_Click()
       Dim strSQL as string
       strSQL = "UPDATE Source, Target SET Target.c = Source.c WHERE Source.a = Target.a AND source.B = Target.b"
      CurrentDB.Execute strSQL, dbFailOnError
End Sub

Open in new window

0
 

Author Closing Comment

by:Conernesto
ID: 39896275
Thank you.
0

Featured Post

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
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 …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Suggested Courses

971 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