Form Update

  • Thread starter Thread starter Gideon
  • Start date Start date
G

Gideon

A main form (main) has a subform (sub). The operator inputs a few
details on main then moves to sub. On exiting sub, i.e. returning to
main, the program validates the data of sub. Assume that the operator
left sub by pushing “Add new Record” on the navigation buttons of main,
and that the data of sub was faulty.
In this case I want to delete the whole record of Main.

I tried BeforeUpdate, AfterUpdate, AfterInsert, and failed.
What should I do?


Gideon Oren
 
Gideon said:
A main form (main) has a subform (sub). The operator inputs a few
details on main then moves to sub. On exiting sub, i.e. returning to
main, the program validates the data of sub. Assume that the operator
left sub by pushing “Add new Record” on the navigation buttons of
main, and that the data of sub was faulty.
In this case I want to delete the whole record of Main.

I tried BeforeUpdate, AfterUpdate, AfterInsert, and failed.
What should I do?


Gideon Oren

It is the nature of a form/subform setup that the record in the form you are
leaving is saved before you enter the other. So the main record is saved when
you move to the subform and all of the events you describe above have already
fired for the main record.

If the subform record is faulty (and thus cannot be saved) then the [Add New
Record] button should never have its code fire. If you are doing validation
over and above that provided by the database engine which does not prevent the
record from being saved, then you need to run that validation in the
BeforeUpdate event of the subform and set Cancel = True when the validation
fails. This will prevent focus from leaving the record until the problem is
corrected.
 
Rick said:
Gideon said:
A main form (main) has a subform (sub). The operator inputs a few
details on main then moves to sub. On exiting sub, i.e. returning to
main, the program validates the data of sub. Assume that the operator
left sub by pushing “Add new Record” on the navigation buttons of
main, and that the data of sub was faulty.
In this case I want to delete the whole record of Main.

I tried BeforeUpdate, AfterUpdate, AfterInsert, and failed.
What should I do?


Gideon Oren


It is the nature of a form/subform setup that the record in the form you are
leaving is saved before you enter the other. So the main record is saved when
you move to the subform and all of the events you describe above have already
fired for the main record.

If the subform record is faulty (and thus cannot be saved) then the [Add New
Record] button should never have its code fire. If you are doing validation
over and above that provided by the database engine which does not prevent the
record from being saved, then you need to run that validation in the
BeforeUpdate event of the subform and set Cancel = True when the validation
fails. This will prevent focus from leaving the record until the problem is
corrected.
Unfortunately, the Subform is a continuous form having a group of
children associated with each record of main. Rather then checking one
record of Subform at a time, I have to ensure that the group of children
meets certain condition (For example that the group is unique and there
is no other group with the same composition of children).
Assume Subform already has a group {A,B,C]. Let's try to create now a
new group {A, B ,C, D}. If I check in Subform before updating every
record, then the operation will be quite lengthy. In addition, before
appending the child {D} of the new group, I have to check if {A,B,C}
already exist. The validation will obviously tell me that the group
already exist.
This is the reason for trying to do the validation on exit of Subform.

But, as I said it did not work.

Thanks

Gideon Oren
 
Gideon said:
Unfortunately, the Subform is a continuous form having a group of
children associated with each record of main. Rather then checking one
record of Subform at a time, I have to ensure that the group of
children meets certain condition (For example that the group is
unique and there is no other group with the same composition of
children). Assume Subform already has a group {A,B,C]. Let's try to create now
a
new group {A, B ,C, D}. If I check in Subform before updating every
record, then the operation will be quite lengthy. In addition, before
appending the child {D} of the new group, I have to check if {A,B,C}
already exist. The validation will obviously tell me that the group
already exist.
This is the reason for trying to do the validation on exit of Subform.

But, as I said it did not work.

The Exit event of a subform control has a Cancel argument. Are you setting that
to True when the validation fails? If you do then that will prevent them from
leaving the subformn until they fix the problem.
 
Back
Top