
Key field violation when comparing two tables
Basically what you want to do is loop through table2 updating the info in
table1.
Dim ws as workspace, db as database, rs1 as recordset, rs2 as recordset
Set WS = Workspaces(0)
Set DB = WS.OpenDatabase("test.mdb")
set rs1 = db.openrecordset("Table1")
set rs2 = db.openrecordset("Table2")
do while not rs2.eof
rs1.findfirst "Key1 = " & rs2.fields("Key1")
if not rs1.nomatch then
rs1.edit
else
rs1.addnew
rs1.fields("key1") = rs2.fields("key1")
endif
rs1.fields("a") = rs2.fields("a")
... 'etc for all the fields
rs1.update
rs2.movenext
loop
--
David W. Forest
LAN Specialist
Information Technologies
Lear Corporation - Ford Division
SBN Level 2
If you're not scared, you don't understand.
Quote:
> Need some assistance. I am trying to update one table using the data
> from another. The table structure is exactly the same. I must use a
> key field. The psuedo code would look something like the following:
> If table 1,field1 equals table 2,field2
> then update field 4, field 6, field 7, field 10
> else append the entire record.
> Not sure where to start on coding this in VB using ACCESS ver 7.0.
> Would appreciate any assistance possible and need it yesterday.
> Thanks.
> Sean