Topic: Save and continue without closing the form

Hello everyone and thank you for reading my new request. Placing a button to save the record after entering data into a form usually closes the form.
On the other hand, considering having to insert more records, I would like to insert a button that saves the record and gives me the possibility of inserting another one, giving me empty fields in the form, without having to reopen the data entry form each time. I hope I made myself clear.
But I don't know how to do it. Could some good soul lend me a hand? Thank you.

2 (edited by sparrow 2023-03-15 14:39:11)

Re: Save and continue without closing the form

Button properties


http://myvisualdatabase.com/help_en/Saverecord.html


Time to read the documentation

Post's attachments

Attachment icon screen.jpg 105.42 kb, 38 downloads since 2023-03-15 

Re: Save and continue without closing the form

Ciao Fabio, Привіт Sparrow
Come stai?
There are a number of options for you.
1.  You could use two buttons (one to save and close the form, one to save and remain on the form).  But I wonder if this might be a bit confusing to the user.
2.  You can save and remain on the form and write a script specifying each field to be cleared but this can be a bit laborious if you have lots of fields.
3.  You can save and remain on the form and write a script that loops through all of the components on the form and clears them (technically, this is probably the 'correct' way to do it).
4.  Or you can cheat - LOL!  You can save and close the form (which will re-set all of the components but then immediately return to the form) - the user will not notice what has happened;  the script for this is probably the easiest of all the options.
And I imagine there are probably a couple of other ways too.
Regards,
Derek.

Post's attachments

Attachment icon clear fields.zip 437.67 kb, 122 downloads since 2023-03-15 

4 (edited by reteinformatica 2023-03-15 17:22:10)

Re: Save and continue without closing the form

sparrow wrote:

Button properties


http://myvisualdatabase.com/help_en/Saverecord.html


Time to read the documentation

Hi sparrows,
thanks for the reply this option does not close the form but does not delete what has already been written in the fields.

Hi Derek, welcome back. I'm fine thanks and you? I'm always grappling with things I don't understand about this program.
I had considered your option number 3 only because you say it is the most correct and I tried with this script:

procedure frmInserimento_bSalvacontinua_OnClick (Sender: TObject; var Cancel: boolean);
var
  i : integer;
begin
  for i:= 0 to frmInserimento.ComponentCount -1 do
     if frmInserimento.Components[i] is TdbEdit then TdbEdit(frmInserimento.Components[i]).Clear;
  for i:= 0 to frmInserimento.ComponentCount -1 do
     if frmInserimento.Components[i] is TdbComboBox then TdbComboBox(frmInserimento.Components[i]).Clear;
  for i:= 0 to frmInserimento.ComponentCount -1 do
     if frmInserimento.Components[i] is TdbStringGridEx Then TdbStringGridEx(frmInserimento.Components[i]).ClearRows;
end;

However, there are two problems:

1) it doesn't save the record despite having set to save in the "Action" section of the properties

2) it deletes the list of comboboxes that are in the form

Post's attachments

Attachment icon Amici della Lirica.zip 471.75 kb, 100 downloads since 2023-03-15 

Re: Save and continue without closing the form

Hi Fabio,
You've got the 'save and add another record' attached to the 'onclick' event.
Try moving it to the 'onafterclick' event and it should be okay.

procedure frmInserimento_bSalvacontinua_OnAfterClick (Sender: TObject);
var
  i : integer;
begin
  for i:= 0 to frmInserimento.ComponentCount -1 do
     if frmInserimento.Components[i] is TdbEdit then TdbEdit(frmInserimento.Components[i]).Clear;
  for i:= 0 to frmInserimento.ComponentCount -1 do
     if frmInserimento.Components[i] is TdbComboBox then TdbComboBox(frmInserimento.Components[i]).Clear;
  for i:= 0 to frmInserimento.ComponentCount -1 do
     if frmInserimento.Components[i] is TdbStringGridEx Then TdbStringGridEx(frmInserimento.Components[i]).ClearRows;
end;

Although I wrote that I think Option 3 is probably the technically 'correct' way to do it, I think I would probably go with Option 4 simply because the script is simpler.

Still, so long as one of the options does what you need, that's the main thing.

One small thing I noticed in your attachment - on the form 'frmavvio' you can click on the label 'INFORMAZIONI';  I do this quite a lot too but I like to change the cursor from an 'arrow' to a 'hand point' when the user moves the mouse across the label.  Maybe it's something you hadn't come across?

Derek.

Post's attachments

Attachment icon fabio screenshot.jpg 117.51 kb, 39 downloads since 2023-03-15 

Re: Save and continue without closing the form

Thanks Derek!
By putting the script in the "onafterclick" event the record is saved but the problem of the list of the two comboboxes vanishing remains. Even closing the form and reopening it in the lists there is no longer any entry, you have to close the program completely.
At this point I really think I'll go with option 4.
Good idea that the cursor becomes a hand, I immediately made this change.

Re: Save and continue without closing the form

Hi Again,
My apologies - I didn't read your original post fully and didn't see the problem with the comboboxes.
This is because in your script, you are clearing out the comboboxes as well as the edit fields.
I think what you need to do is reset the comboboxes to -1 - try it like this

procedure frmInserimento_bSalvacontinua_OnAfterClick (Sender: TObject);
var
  i : integer;
begin
  for i:= 0 to frmInserimento.ComponentCount -1 do
     if frmInserimento.Components[i] is TdbEdit then TdbEdit(frmInserimento.Components[i]).Clear;
  for i:= 0 to frmInserimento.ComponentCount -1 do
     if frmInserimento.Components[i] is TdbComboBox then TdbComboBox(frmInserimento.Components[i]).dbitemid := -1;
end;

I'd also remove the lines about 'tdbstringgridex as it just confuses things (well, it confuses me!!) as you don't have any tablegrids in form 'frminserimento'
Derek.

Re: Save and continue without closing the form

Ah sure, the lines concerning the tablegrid ended up there because I had copied and pasted from the first form where there is also the tablegrid and I forgot to delete it.
Perfect so it works great. Thank you so much derek you are always number one.