Key field violation when comparing two tables 
Author Message
 Key field violation when comparing two tables

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



Tue, 13 Jul 1999 03:00:00 GMT  
 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



Fri, 16 Jul 1999 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. comparing data in specific fields from two tables ???

2. Comparing two tables and then updating one table.

3. Having trouble accessing single field key with two concatenated fields

4. How to Compare Tables, Fields, & Field Properties

5. Comparing Two Access Tables?

6. comparing two tables

7. Comparing Two Tables

8. Compare two access databases, size of tables

9. compare two fields values

10. Comparing two data fields in Access through Visual Basic

11. comparing field values from two different access databases

12. VB - Compare two list box items - display the matched fields in list3

 

 
Powered by phpBB® Forum Software