Solved

Access update one tbl with contents from anohter tbl

Posted on 2014-02-28
6
278 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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

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 500 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

821 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