Topic: What is the simplest way to copy a record in a table without coding

Hi everyone
I have a problem, perhaps stupid, but ?
My attempt attached.
Iif anyone has a solution  ?

Re: What is the simplest way to copy a record in a table without coding

You forgot the attachment.

On a clear disk you can seek forever

Re: What is the simplest way to copy a record in a table without coding

sorry. file to large for upload

Post's attachments

Attachment icon CopyRecord.7z 274.01 kb, 29 downloads since 2024-04-09 

Re: What is the simplest way to copy a record in a table without coding

Hi,
Yes, it is possible (sort of!) without any code.
Have a look at the attachment.
TO CREATE a record
1.  click on the 'create' button
2.  enter your details
3.  click 'copy/save' to save your new record
4.  close the form.
To EDIT a record
1.  double-click on the row in the tablegrid you want to edit
2.  make any changes and click 'copysave' to save your changes
3.  close the form
To COPY a record
1.  double-click on the row in the tablegrid you want to edit
2.  click 'copy/save' first (this prevents the selected row from being overwritten
3.  make any changes (if creating a copy BASED on the selected row) and / or just click 'copy/save' to create your new record.
It sounds a bit complicated but just try it out in the attachment and it should be straightforward.
Just be careful when doing this as it is very easy to create duplicate records unintentionally.
Regards,
Derek.

Post's attachments

Attachment icon CopyRecord2.zip 436.14 kb, 35 downloads since 2024-04-09 

Re: What is the simplest way to copy a record in a table without coding

thanks Derek
Now I see that I should have just unchecked "Close the current form after saving". The only thing you need to recognize is the "New record" mode, and after that close the form manually.

6 (edited by k245 2024-04-10 09:48:32)

Re: What is the simplest way to copy a record in a table without coding

Universal Copy
https://k245.ru/wp-content/uploads/2023/04/dvojnyashki.jpg

To copy a record you need very little code


function DB_CopyRecord( ATableName: string; AID: integer ):integer;
// universal function for copying a record
begin
   // create a temporary table with a structure identical to the copied record
   SQLExecute('CREATE TEMPORARY TABLE tmp AS SELECT * FROM ['+ATableName+'] WHERE id = '+IntToStr(AID));
   // reset the value of the ID field
   SQLExecute('UPDATE tmp SET id = NULL');
   // insert record back
   SQLExecute('INSERT INTO ['+ATableName+'] SELECT * FROM tmp');
   // get the ID of the new entry
   Result := Last_Insert_ID();
   // delete temporary table
   SQLExecute('DROP TABLE tmp');
end;

https://k245.ru/en/mvdb-en/universal-copy.html

Визуальное программирование: блог и телеграм-канал.