Validation and subforms

B

BruceM

I have a form with a subform. I am using validation in the form's Before
Update event to assure required fields are filled in. However, when I click
into the subform the record is saved, and the Before Update code runs before
I'm ready for it. Is there a way, short of hiding the subform, that I can
allow the user to click into the subform without producing a message that a
required field is missing a value? The logical flow of things is to select
the subform values fairly early in the process of entering a record, rather
than after everything else is complete, which is why hiding the subform
would be awkward.

This outlines the problem. The rest of this posting describes how I have
attempted to solve it.

I have an awkward workaround that involves a boolean being set to True or
False under different circumstances. If it is True, the rest of the Before
Update code is skipped. The form is divided into sections; each section
either needs to be complete or not started. If it is not started, the
boolean is set to True, and the rest of Before Update is skipped.

I can set the boolean to True if the record is new (which is the only time
when the subform comes into play). With it set to True Before Update will
be skipped. The user can click into the subform without invoking the Before
Update code. When the user clicks into one of the other text boxes (Text1,
Text2, and Text3) in the first section, the boolean is set to False. The
next time the user attempts to save the record, the Before Update code will
run because the boolean is False. The trouble is that if the user clicks
into Text1 (thus setting the boolean to False), then clicks into the
subform, Before Update will produce an error message that Text2 and Text3
need to be filled in.

Training should be able to solve this, but unfortunately I cannot count on
it, for reasons that would make me sound bitter were I to describe them.
 
M

Marshall Barton

BruceM said:
I have a form with a subform. I am using validation in the form's Before
Update event to assure required fields are filled in. However, when I click
into the subform the record is saved, and the Before Update code runs before
I'm ready for it. Is there a way, short of hiding the subform, that I can
allow the user to click into the subform without producing a message that a
required field is missing a value? The logical flow of things is to select
the subform values fairly early in the process of entering a record, rather
than after everything else is complete, which is why hiding the subform
would be awkward.

This outlines the problem. The rest of this posting describes how I have
attempted to solve it.

I have an awkward workaround that involves a boolean being set to True or
False under different circumstances. If it is True, the rest of the Before
Update code is skipped. The form is divided into sections; each section
either needs to be complete or not started. If it is not started, the
boolean is set to True, and the rest of Before Update is skipped.

I can set the boolean to True if the record is new (which is the only time
when the subform comes into play). With it set to True Before Update will
be skipped. The user can click into the subform without invoking the Before
Update code. When the user clicks into one of the other text boxes (Text1,
Text2, and Text3) in the first section, the boolean is set to False. The
next time the user attempts to save the record, the Before Update code will
run because the boolean is False. The trouble is that if the user clicks
into Text1 (thus setting the boolean to False), then clicks into the
subform, Before Update will produce an error message that Text2 and Text3
need to be filled in.

Training should be able to solve this, but unfortunately I cannot count on
it, for reasons that would make me sound bitter were I to describe them.


Besides untrainable user's, this problem is caused by the
requirement to complete data entry before completing a
section or subform. Normally, it should be near irrelevant
what order data is entered, even over multiple sessions.

I think you need to add another flag for the subform to set
when it is "done". You can do this by adding a Public
variable to the main form's declarations section so the
subform can set it using Parent.variable = False
 
B

BruceM

If it makes any difference, there are two subforms. One is for Reason(s);
it is required. The other is for PartNumber; it may not be needed at all.

I don't quite follow what you mean by setting the variable. Do you mean I
should set it to False in the subform control's Exit event, or something
like that? If that variable is the Boolean I described, and if it is set to
True in the form's Current event, the Before Update code won't run until it
is set to False, so I sort of see how that could work (it would also have to
be set to False in the GotFocus (Enter?Change?) event of each of the three
text boxes (Text1, 2, and 3) on the main form). However, if the user makes
an entry in Text1, then tries to go to the subform, the Before Update code
will run and generate an error message because Text 2 and Text 3 are still
blank. I can compel the user to make a Reason selection in the subform
before entering anything into Text1, 2, or 3, but what about the optional
(PartNumber) subform? If the user makes a Reason entry, the variable is set
to False, but if the user then clicks into PartNumber the variable is False,
and Before Update runs.

Or am I missing your point?
 
M

Marshall Barton

I was suggesting that you should try using a separate flag
for each "section" that must be completed once started. The
main form's BeforeUpdate can then check only the section
that has been started.
--
Marsh
MVP [MS Access]

If it makes any difference, there are two subforms. One is for Reason(s);
it is required. The other is for PartNumber; it may not be needed at all.

I don't quite follow what you mean by setting the variable. Do you mean I
should set it to False in the subform control's Exit event, or something
like that? If that variable is the Boolean I described, and if it is set to
True in the form's Current event, the Before Update code won't run until it
is set to False, so I sort of see how that could work (it would also have to
be set to False in the GotFocus (Enter?Change?) event of each of the three
text boxes (Text1, 2, and 3) on the main form). However, if the user makes
an entry in Text1, then tries to go to the subform, the Before Update code
will run and generate an error message because Text 2 and Text 3 are still
blank. I can compel the user to make a Reason selection in the subform
before entering anything into Text1, 2, or 3, but what about the optional
(PartNumber) subform? If the user makes a Reason entry, the variable is set
to False, but if the user then clicks into PartNumber the variable is False,
and Before Update runs.

Or am I missing your point?

BruceM said:
I have a form with a subform. I am using validation in the form's Before
Update event to assure required fields are filled in. However, when I
click into the subform the record is saved, and the Before Update code runs
before I'm ready for it. Is there a way, short of hiding the subform, that I can
allow the user to click into the subform without producing a message that
a required field is missing a value? The logical flow of things is to
select the subform values fairly early in the process of entering a record,
rather than after everything else is complete, which is why hiding the subform
would be awkward.

This outlines the problem. The rest of this posting describes how I have
attempted to solve it.

I have an awkward workaround that involves a boolean being set to True or
False under different circumstances. If it is True, the rest of the
Before Update code is skipped. The form is divided into sections; each section
either needs to be complete or not started. If it is not started, the
boolean is set to True, and the rest of Before Update is skipped.

I can set the boolean to True if the record is new (which is the only time
when the subform comes into play). With it set to True Before Update will
be skipped. The user can click into the subform without invoking the
Before Update code. When the user clicks into one of the other text boxes
(Text1, Text2, and Text3) in the first section, the boolean is set to False. The
next time the user attempts to save the record, the Before Update code
will run because the boolean is False. The trouble is that if the user clicks
into Text1 (thus setting the boolean to False), then clicks into the
subform, Before Update will produce an error message that Text2 and Text3
need to be filled in.
[]

I think you need to add another flag for the subform to set
when it is "done". You can do this by adding a Public
variable to the main form's declarations section so the
subform can set it using Parent.variable = False
 
B

BruceM

Ah, now I understand. Validate each "section" separately, rather than the
whole thing in one shot. Sounds like it will do the trick. Thanks for the
suggestion.

Marshall Barton said:
I was suggesting that you should try using a separate flag
for each "section" that must be completed once started. The
main form's BeforeUpdate can then check only the section
that has been started.
--
Marsh
MVP [MS Access]

If it makes any difference, there are two subforms. One is for Reason(s);
it is required. The other is for PartNumber; it may not be needed at all.

I don't quite follow what you mean by setting the variable. Do you mean I
should set it to False in the subform control's Exit event, or something
like that? If that variable is the Boolean I described, and if it is set
to
True in the form's Current event, the Before Update code won't run until
it
is set to False, so I sort of see how that could work (it would also have
to
be set to False in the GotFocus (Enter?Change?) event of each of the three
text boxes (Text1, 2, and 3) on the main form). However, if the user
makes
an entry in Text1, then tries to go to the subform, the Before Update code
will run and generate an error message because Text 2 and Text 3 are still
blank. I can compel the user to make a Reason selection in the subform
before entering anything into Text1, 2, or 3, but what about the optional
(PartNumber) subform? If the user makes a Reason entry, the variable is
set
to False, but if the user then clicks into PartNumber the variable is
False,
and Before Update runs.

Or am I missing your point?

BruceM wrote:

I have a form with a subform. I am using validation in the form's
Before
Update event to assure required fields are filled in. However, when I
click into the subform the record is saved, and the Before Update code
runs
before I'm ready for it. Is there a way, short of hiding the subform,
that I can
allow the user to click into the subform without producing a message
that
a required field is missing a value? The logical flow of things is to
select the subform values fairly early in the process of entering a
record,
rather than after everything else is complete, which is why hiding the
subform
would be awkward.

This outlines the problem. The rest of this posting describes how I
have
attempted to solve it.

I have an awkward workaround that involves a boolean being set to True
or
False under different circumstances. If it is True, the rest of the
Before Update code is skipped. The form is divided into sections; each
section
either needs to be complete or not started. If it is not started, the
boolean is set to True, and the rest of Before Update is skipped.

I can set the boolean to True if the record is new (which is the only
time
when the subform comes into play). With it set to True Before Update
will
be skipped. The user can click into the subform without invoking the
Before Update code. When the user clicks into one of the other text
boxes
(Text1, Text2, and Text3) in the first section, the boolean is set to
False. The
next time the user attempts to save the record, the Before Update code
will run because the boolean is False. The trouble is that if the user
clicks
into Text1 (thus setting the boolean to False), then clicks into the
subform, Before Update will produce an error message that Text2 and
Text3
need to be filled in. []

I think you need to add another flag for the subform to set
when it is "done". You can do this by adding a Public
variable to the main form's declarations section so the
subform can set it using Parent.variable = False
 

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