Anne said:
I have a form with a subform, the main form generates a unique
identifyer for the record on form open.
If nothing is entered in the subform, I don't want the record on the
main form saved.
How can I keep it from saving?
Sorry - I know this is probably easy but I have "Friday brain".
Thanks.
It's not as easy as all that, so maybe your brain is okay. If the focus
ever goes to the subform, the main form will be saved, and there's
nothing you can do to stop it. You *can* do these things:
1. Instead of setting the value of the main form's key in the form's
Open event, you can set that control's DefaultValue property instead.
That way the form won't be "dirty", so if the focus *doesn't* go to the
subform, and the user just closes the main form, the record won't be
saved.
2. If necessary, you might use the Exit event of the subform control (on
the main form) to check whether any subform record was added for this
main-form record. If not, you can delete the main-form record. That's
not really safe unless there's no main-form record is ever supposed to
exist without a subform record.
3. Similarly, and as an alternative, you could use the main form's Close
event to run a delete query that deletes all main-form records that
don't at least one matching subform record. Again, you can only do this
if there's a logical rule that says no main-form record should ever
exist without a matching subform record.