Validate while Closing the Form

Dear Friends,

In My Form, Header and Lines are there. when i open the form, Line records will be inserted default. And one field is Mandatory in Lines record.

When i close the form, I need validate that Field. If that field is empty in any record, it should throw error & Form should not be closed…

where should i write the validation? any ideas?

Thanks in Advance.

Override the canClose() on the form.
write down your validation,
return true – when condition satisfies and you wanna close the form
return false --when condition not satisfies and you don’t wanna close the form and give a message

Does it mean that you’re inserting line records with a mandatory field empty (bypassing the validation that prevents that)? It looks wrong - either the field is mandatory and you shouldn’t insert such records, or it shouldn’t be marked as mandatory.

Thanks Krishna.

But form should not be closed…!

Thanks Martin.

is there any way to validate while closing the Form?

What’s the issue.
implement the logic where form should not be closed & return false.