Replicating Record

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

Guest

I have a form, with fields bound, via a query, to two separate tables. There is an occasional need to replicate the current record, via a control button on the form, preserving the values of all save two of the existing fields. The easiest solution would seem to be to create an exact facsimile of the current record, and then programmatically clear the two fields in question, ready for the input of new values, but I cannot find a simple way of doing this. I have successfully created a new record, with ‘DoCmd.GoToRecord , , acNewRec’ but all its fields are, of course, null. The only way I can populate those fields is to copy the contents of each field into public ‘buffer’ variables, before running the GoToRecord command, and then copy them back again afterwards. That means creating a whole set of buffer variables, of all different types, specifically for the purpose, and then writing nearly a page of code to effect the copying process. It works just fine, but could hardly be described as elegant. There must surely be a better solution?
 
I have a form, with fields bound, via a query, to two separate tables. There is an occasional need to replicate the current record, via a control button on the form, preserving the values of all save two of the existing fields. The easiest solution would seem to be to create an exact facsimile of the current record, and then programmatically clear the two fields in question, ready for the input of new values, but I cannot find a simple way of doing this. I have successfully created a new record, with ‘DoCmd.GoToRecord , , acNewRec’ but all its fields are, of course, null. The only way I can populate those fields is to copy the contents of each field into public ‘buffer’ variables, before running the GoToRecord command, and then copy them back again afterwards. That means creating a whole set of buffer variables, of all different types, specifically for the purpose, and then writing nearly a page of code to effect the copying process. It works just fine, but could hardly be
described as elegant. There must surely be a better solution?

I'd suggest having the button run an Append query appending the
currently selected record (less the two fields) to the table, and then
navigating to the newly created record.
 
You could create a temporary table, copy the record, run the fields, but
that is likely as much or more work than simply defining Form-module level
variables, filling them, and moving the values to the new record.

Larry Linson
Microsoft Access MVP

Peter Hallett said:
I have a form, with fields bound, via a query, to two separate tables.
There is an occasional need to replicate the current record, via a control
button on the form, preserving the values of all save two of the existing
fields. The easiest solution would seem to be to create an exact facsimile
of the current record, and then programmatically clear the two fields in
question, ready for the input of new values, but I cannot find a simple way
of doing this. I have successfully created a new record, with
'DoCmd.GoToRecord , , acNewRec' but all its fields are, of course, null.
The only way I can populate those fields is to copy the contents of each
field into public 'buffer' variables, before running the GoToRecord command,
and then copy them back again afterwards. That means creating a whole set
of buffer variables, of all different types, specifically for the purpose,
and then writing nearly a page of code to effect the copying process. It
works just fine, but could hardly be described as elegant. There must
surely be a better solution?
 
Back
Top