Page 1 of 1

Problem saving Form with SubForm

Posted: Tue Feb 06, 2024 11:29 pm
by calida82
Hi I'm having a problem saving a form that has a subform. If the main form is a new record, the records inserted in the subform are not saved. if the main form is not a new record the subform records are saved. why does this happen? what am I doing wrong?

Re: Problem saving Form with SubForm

Posted: Wed Feb 07, 2024 6:37 am
by kev1n
Please check this topic:

viewtopic.php?p=28989#p28989

Re: Problem saving Form with SubForm

Posted: Wed Feb 07, 2024 6:55 am
by calida82
good morning, I checked that post, I had opened it but it's not the same problem. That case didn't save me because I didn't fill in all the fields of the record. here things are different. The new main form record is saved, what is not saved are the subform records. when you save what is the module or submodule saved first? perhaps the subform fields are not saved because the form, being a new record, does not yet have an id and therefore the foreign key of the subform records remains empty?

Re: Problem saving Form with SubForm

Posted: Wed Feb 07, 2024 7:31 am
by kev1n
Quoting my reply from the other topic:
With regards to the record not saving, are you using auto increment and is the primary key set in mysql. can you show the the table structure?

Re: Problem saving Form with SubForm

Posted: Wed Feb 07, 2024 7:15 pm
by calida82
sorry... yes I have a database with autoincrement primary key. is there a special way for this or before saving do I have to get the last record add one and fill in the field manually?

Re: Problem saving Form with SubForm

Posted: Wed Feb 07, 2024 10:17 pm
by calida82
I tried to make the id field of the main form visible and editable, I checked the last id in phpmyadmin and manually inserted the last number + 1 into the field as I intended to do with the code in beforeSave, then I filled in the main form and inserted some records in the subform then saved. the form is correctly saved with the id I entered manually, but the subform records are still not saved...

Re: Problem saving Form with SubForm

Posted: Thu Feb 08, 2024 7:44 am
by kev1n
Subforms do not work with auto increment pks.

Re: Problem saving Form with SubForm

Posted: Tue Feb 13, 2024 6:59 am
by calida82
For the moment I solved with

Code: Select all

if(nuIsNewRecord()){
	nuActionSave();
}
So I get the ID immediatly and the subform records are saved regularly

Re: Problem saving Form with SubForm

Posted: Tue Feb 13, 2024 8:26 pm
by nc07
kev1n wrote: Thu Feb 08, 2024 7:44 am Subforms do not work with auto increment pks.
It only works if the parent form has been saved before subform data is filled.

Re: Problem saving Form with SubForm

Posted: Wed Feb 14, 2024 8:43 am
by kev1n
I have also experienced the problem with subforms that use auto increment that sometimes random records in the subform are not saved. I haven't looked into this recently and I'm not even sure I could replicate that issue. This has led me to believe that subforms do not work well with auto increment keys.