update / append for MDin VB

  • Thread starter Thread starter Sergey Bogdanov
  • Start date Start date
S

Sergey Bogdanov

Hello,

Suppose that I'd like to make any calculations which are based on Table1 and
put result for it to Table2, but before put I'd like to ensure that this
table is needed for append (the record which I'm going to put into this
table is not exist), otherwise I'd like just to Update this record.

Are there any easy methods for that? How can I easy detect that the record
with the following data is there?

--Sergey
 
Sergey said:
Suppose that I'd like to make any calculations which are based on Table1 and
put result for it to Table2, but before put I'd like to ensure that this
table is needed for append (the record which I'm going to put into this
table is not exist), otherwise I'd like just to Update this record.

Are there any easy methods for that? How can I easy detect that the record
with the following data is there?

Assuming that a variable (let's name it lngPK) contains the
primary key of the record to be updated or added. Then a
general outline of the code could be:

Set rs = db.OpenRecordset("SELECT * FROM Table2 " _
& "WHERE keyfield = " & lnkPK, dbOpenDynaset)
If rs.RecordCount > 0 Then
rs.Edit
Else
rs.AddNew
rs!keyfield = lnkPK
rs!somefield = whatever
End If
rs!calculatedfield = thenewvalue
rs.Update
rs.Close : Set rs = Nothing
 
Back
Top