Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to save a field from one table to another table using code

Status
Not open for further replies.

mflower

MIS
May 6, 2001
52
NZ
I think this could be a silly question as it would seem so easy to most programmers..but what's the code for saving a particular field in Table 1 to Table 2. For instance, I want to save FirstName from Table A to FirstName in TableB.
Thanks.
 
Hi!

It are lot of ways to do it. I'll present one of them with using recordsets.

dim rstA as recordset
dim rstB as recordset
dim strMyCriteria as string


'On the supposition that we have form with textBox PersonID
strMyCriteria = me.PersonID '
set rstA=currentdb,openrecordset("Select * From TableA Where " & strMyCriteria & ";"

set rstB=currentdb,openrecordset("Select * From TableA;)
rstB.addnew
rstB!FirstName = rstA.FirstName

'You can update other fields like FirstName, too.
rstB.update
rstA.close
rstB.close
set rstA=Nothing
set rstB=Nothing


Other way: you can create Append query (Insert SQL):

INSERT INTO TableB ( FirstName , OtherField)
SELECT TableA.FirstName , TableA.OtherField
FROM TableA
WHERE TableA.FirstName ="John";

etc.


Aivars
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top