Update record in table

wikus

Active Member
Joined
May 2, 2010
Messages
320
Office Version
  1. 365
Can somebody perhaps help with VBA code to update a second table with a record selected if first table.
I have 2 tables, Prospects and Clients tables. I want to select a Prospect and it must be appended in the Client table and marked as moved to Clients in the Prospect table.
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Shown below is how to use an Update using VBA with an SQL statement.

<font face=Courier New><SPAN style="color:#00007F">Function</SPAN> sqlUWRCode()<br>DoCmd.SetWarnings <SPAN style="color:#00007F">False</SPAN><br>sql = "UPDATE [XIAP Stub dataset New] INNER JOIN [Underwriter Codes] ON [XIAP Stub dataset New].[Uwr ID Code] = [Underwriter Codes].[Initials]"<br>sql = sql & "SET [XIAP Stub dataset New].[Uwr ID Code] = [Underwriter Codes]![XIAP Code];" <SPAN style="color:#007F00">' The table to update 'the field and content to add</SPAN><br>Debug.Print sql<br>DoCmd.RunSQL sql<br>DoCmd.SetWarnings <SPAN style="color:#00007F">True</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Function</SPAN></FONT>


Second sample

Function sqlParticipant2()
DoCmd.SetWarnings False
Dim sql As String
sql = "UPDATE [XIAP Stub dataset New] " 'The Table to Update
sql = sql & "SET [XIAP Stub dataset New].[Participant 2]='PRC040'" 'The field and content to add
sql = sql & "WHERE [XIAP Stub dataset New].[Participant 2]<>''" 'The Field and the current content to change
Debug.Print sql
DoCmd.RunSQL sql
DoCmd.SetWarnings False
End Function
One way you can do this, is create a query and convert it to Update, then look at the SQL code and you have the SQL side to then add in a VBA statement like the above.
 
Last edited:
Upvote 0
Your welcome I hope it helps find a solution if not post back.
 
Upvote 0

Forum statistics

Threads
1,224,508
Messages
6,179,189
Members
452,893
Latest member
denay

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top