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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Database update?

Status
Not open for further replies.
Oct 22, 2001
215
US
I need an easy way to update a database where VB is used to insert record from an Acces table. The criteria is to compare the old data (I got an old table and a new table and data is inserted to new table) w the new data and if it is not there then do the insert and if it is there then modify it (Assuming something changed..)

I want to do this in one step either using SQL or VB whatever easy way it can be..
TIA
 
The way I would do this is to create a procedure something like this:
Code:
sub AddToNewTable(aValue as string,AnotherVal as Integer...)
  With currentDb.OpenRecordset("NewTable",dbOpenDynaset)
      .FindFirst "Field1='" & aValue & "' AND Field2=" & AnotherVal
      if .NoMatch then
          .AddNew
          !Field1=aValue
          !Field2=AnotherVal
          .update
       else
          .Edit
          ...
          .Update
       Endif
   end with
end sub
Now you just need to pass you're parameters to this function and it will do the update/append for you, something like:
Code:
with currentdb.OpenRecordset("TableOld",dbopensnapshot)
  [italics]you can iterate through if you want or something[/italics]
  AddtoNewTable !Field1,!Field2
end with

I hope this helps,
Rewdee

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top