I wrote a code whose task is to add and edit on the same form. I wonder if it could be written better, maybe there is another solution?
You can make the form passive. In this case, the calling code uses either an existing record or creates a new one. Then it calls the edit form for this entry. And if the cancellation has passed, it deletes the new entry.