update / append for MDin VB

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
 
M

Marshall Barton

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top