Subform saving when tabbing from main form (Access 97)

J

Joan Edington

Hi,

I've been reading this group all day looking for someone with my
problem but everyone else seems to have the opposite happening.

I have a form which contains a subform. The format is the mainform
stuff on page 0 of a tabbed control, the subform on page 1 tab.

On the tab_control's change event I set a field on the subform to a
value on the main form.

I enter the relevant data on the mainform page 0 then click on the tab
to move to page 1. The mainform record is automatically saved, as
expected, and the subform appears with the field filled in, also as
expected.

However, it dropped into my validation routine for the subform and
immediately displayed an error message saying that fields can't be
blank etc. I didn't expect the subform to try and save automatically
at that point.

I put msgboxes in my events on both the mainform and subform to try
and track what was happening and this is the sequence of events from
creating a new mainform.

1. Subform_OnCurrent.
2. Mainform_OnCurrent.

I enter data then click on the tab for the page containing the
subform.

3. Mainform_ BeforeUpdate.
4. Subform_OnCurrent.
5. Subform_BeforeUpdate.

This gives the validation error because I've not had a chance to enter
anything. I say OK to cancel the save.

6. TabControl_Change.

Basically my questions are:-

Why does the subform save at this point?
Why is it dirty anyway when the code to change the field isn't
actioned until after the save?
Is there any way to stop the save of the subform record?

All I want to do is to have the mainform record saved and the subform
open for input, but with that one field pre-set. It doesn't sound like
rocket science but I'm well stumped.

Any help would be very greatly received.

Thanks.

Joan Edington
 
D

Dave Jones

Hi Joan,

Filling in the field on the sub form makes the sub form
dirty (i.e. there have been changes) and therefore the
changes will be saved at some time if you don't cancel the
Before Update event. I have never tried using two pages on
a tab control, one for the main form data and the other
for a sub form (Usually a subform control is on the main
form linked by two fields) and suspect that the change
event on the tab control together with the fact that the
page which you are moving to on the Tab control
becomes 'Dirty' as soon as it opens is invoking the the
save. One of the MVPs might know better.
hth

Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top