Cloning a record

  • Thread starter Thread starter Gary Schuldt
  • Start date Start date
G

Gary Schuldt

frmA is displaying record r1 from tA

What I want to do is create a new record r2 with all its fields (except the
autonumber ID, of course) filled in to be the same values as those in r1 . .
..

. . . and then display r2 using frmA.

From that point I'll modify the values of r2 which are different from r1 and
save it.

(The reason for doing this is that modifying the values which are different
will take less time for the user than keying in all the values for r2 from
scratch.)

I'm thinking that there's probably a "good practice" way to do this and
would like to know what it is!

Thanks in advance.

Gary
 
Gary Schuldt said:
frmA is displaying record r1 from tA

What I want to do is create a new record r2 with all its fields
(except the autonumber ID, of course) filled in to be the same values
as those in r1 . . .

. . . and then display r2 using frmA.

From that point I'll modify the values of r2 which are different from
r1 and save it.

(The reason for doing this is that modifying the values which are
different will take less time for the user than keying in all the
values for r2 from scratch.)

I'm thinking that there's probably a "good practice" way to do this
and would like to know what it is!

Thanks in advance.

Gary

The command button wizard will build a button to do this for you. The
wizard's code may not be the best -- as I recall it uses the DoMenuItem
method to perform the necessary actions via the menu options -- but I
think the actions boil down to:

RunCommand acCmdSelectRecord
RunCommand acCmdCopy
RunCommand acCmdPasteAppend

I can't remember whether the PasteAppend action automatically saves the
new record you created before you get to edit it, or not. If so, you
may want to use

RunCommand acCmdSelectRecord
RunCommand acCmdCopy
RunCommand acCmdRecordsGoToNew
RunCommand acCmdPaste

instead. Either way, you could edit the record after it has been
copied.
 
The desire to clone records, sometimes indicates an unnormalized database
structure. If there are more unchanged values than changed ones - as you
say - then, the unchanged ones should maybe go in a seperate table, with a
one-to-many relationship to the changed values in the existing table.

HTH,
TC
 
Thanks, TC

I'm glad there are people out there who recognize patterns that might
indicate an unnormalized database--it means what I've been teaching in my
classes for 25 years is being practiced somewhere!

In this case, a lot of the fields being cloned are foreign keys, as well as
stuff you wouldn't create a separate table for anyway in this application
(such as size of pot in which the plant was purchased).

Gary
 
Hi, Dirk,

OK, I used the command button wizard, and here's the code:

===============================
Private Sub CloneRecord_Click()
On Error GoTo Err_CloneRecord_Click


DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 2, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 5, , acMenuVer70 'Paste Append

=============================

Give me a way to convert the actions in the code above to something readable
(like what you suggested below!).

Is there a way to get the wizard to generate code in the readable style you
wrote below instead of the cryptic stuff above, with it's 8's, 2's, and 5's?

Also, when the code above runs, it triggers an AfterUpdate event on Combo8
(a control on the form), which, in this scenario, doesn't make sense and
Combo8's AfterUpdate macro aborts. Any quick suggestions on how to avoid
the abort?

Gary
 
Thanks, Dirk:

Now, to finish this up, I need to know how to get the ID of the cloned
record so I can work with it.

Thanks.

Gary
 
Back
Top