How to create a command button to do...

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

i'm trying to create a command button in a form doing the following task:

copy a particular record from one table, then paste info of that particular
record into another table? the target table has the same layout as the source
table.


any help is appreciated...
 
Well, this one has been discussed several times in the past few days.
Also, try using Google, you'ld be amazed at what a search engine can do
for you.

The logical question is; why would you want to copy data into 2
different tables? Redundancy is the sign of a seriously flawed
database setup. Try re-thinking your database design or you'll have
nothing but headaches in the future.
 
thanks. what was the title that i can look into?

by the way, the reason for having two tables is to keep track of any changes
we are making to the original dataset. for audit purpose, we need to maintain
the original data as they are, but save any modification in a separate table.
is it making sense?
 
So if you change data in one record 3 times, you need all of the
changes saved 3 times? Why not just use a "Notes" field to store the
changes (i.e. "Mary changed Units from 2 to 6 on 7/30/2006") and then
you can create a Notes table and join it to the original table via an
ID field?

I guess if it absolutely has to be done the way you described you could
do something along these lines:

dim db as database
dim rec, rec2 as recordset

set db = currentdb
set rec = db.openrecordset("select * from Table1 where RecordID = " &
me.RecordID)
set rec2 = db.openrecordset("Table2")

rec2.addnew
' See ** below
rec2("Field1") = rec("Field1")
rec2("Field2") = rec("Field2")
etc...
rec2.update

The above assumes your record has an ID field that will make it easier
to select the exact record you want to duplicate.

** There should be an easier way to do this by looping through
FieldDefs, you might want to do a search on that. If you have alot of
fields in the table then FieldDefs is the way to go.
 
Back
Top