Required Field Msg Box loops. Can't close form...help

S

sdh31873

I have a form with some required fields. When they fail to enter data in
that field, it pops up a message box. It takes them back to that field.
What if they don't know the information and they want to close the form? I
can't get that to work. I have added a "Close Form" button but it won't stop
prompting with the msgbox from the required field. Any help in this matter?
Here is the code. Thanks.

Code:
Private Sub ContactName_Exit(cancel As Integer)
If IsNull(Me.ContactName) = True Then
MsgBox "The Contact Name is required", vbExclamation, "Missing Data"
cancel = True
Me!ContactName.SetFocus
Exit Sub
End If

End Sub
 
M

Marshall Barton

sdh31873 said:
I have a form with some required fields. When they fail to enter data in
that field, it pops up a message box. It takes them back to that field.
What if they don't know the information and they want to close the form? I
can't get that to work. I have added a "Close Form" button but it won't stop
prompting with the msgbox from the required field. Any help in this matter?
Here is the code. Thanks.

Code:
Private Sub ContactName_Exit(cancel As Integer)
If IsNull(Me.ContactName) = True Then
MsgBox "The Contact Name is required", vbExclamation, "Missing Data"
cancel = True
Me!ContactName.SetFocus
Exit Sub
End If

End Sub


It's difficult to have a "required" field and try to deal
with a user that doesn't know what to enter. It sounds like
the field isn't really required.

You could try removing the Cancel and SetFocus. However,
the msgbox will pop up even if the user is just tabbing
through the text boxes to get to the one they want to use.

For that reason, it is more common to use the Form's
BeforeUpdate event instead of individual control events.
However, if the user doesn't know what to enter, all you can
do is pop up a warning. If the "doen't know" scenario is
moderately common, users will quickly learn to ignore the
warning, rendering it useless.

I prefer to let users enter data in any order at any time
(even over several days). I provide a button that users can
click to say they think the quote/order/whatever is complete
and can be made "official". The button's Click event
procedure would the check all the required fields, generate
a message about the missing ones and skip the make it
official step.

If everthing checks out ok, then set a OfficialDate field to
Now() so you know the entry is complete (and maybe should
not be changed anymore).
 
S

sdh31873

I love the code that was provided to check all the fields beforeupdate on the
form event but I have a subform included. I need it to check all of those
too. Any help there?



Marshall said:
I have a form with some required fields. When they fail to enter data in
that field, it pops up a message box. It takes them back to that field.
[quoted text clipped - 12 lines]
End Sub[/code]

It's difficult to have a "required" field and try to deal
with a user that doesn't know what to enter. It sounds like
the field isn't really required.

You could try removing the Cancel and SetFocus. However,
the msgbox will pop up even if the user is just tabbing
through the text boxes to get to the one they want to use.

For that reason, it is more common to use the Form's
BeforeUpdate event instead of individual control events.
However, if the user doesn't know what to enter, all you can
do is pop up a warning. If the "doen't know" scenario is
moderately common, users will quickly learn to ignore the
warning, rendering it useless.

I prefer to let users enter data in any order at any time
(even over several days). I provide a button that users can
click to say they think the quote/order/whatever is complete
and can be made "official". The button's Click event
procedure would the check all the required fields, generate
a message about the missing ones and skip the make it
official step.

If everthing checks out ok, then set a OfficialDate field to
Now() so you know the entry is complete (and maybe should
not be changed anymore).
 
M

Marshall Barton

I can't see anything with BeforeUpdate code, but, regardless
of what it does, it can not deal with a user that doesn't
know what to enter at that time.

If you're happy with that approach, then add similar code to
the subform's BeforeUpdate event. You can not do the
subform checking in the main form because the subform
record, if changed, will be saved before the focus is given
to the mainform.
--
Marsh
MVP [MS Access]

I love the code that was provided to check all the fields beforeupdate on the
form event but I have a subform included. I need it to check all of those
too.

I have a form with some required fields. When they fail to enter data in
that field, it pops up a message box. It takes them back to that field.
[quoted text clipped - 12 lines]
End Sub[/code]
Marshall said:
It's difficult to have a "required" field and try to deal
with a user that doesn't know what to enter. It sounds like
the field isn't really required.

You could try removing the Cancel and SetFocus. However,
the msgbox will pop up even if the user is just tabbing
through the text boxes to get to the one they want to use.

For that reason, it is more common to use the Form's
BeforeUpdate event instead of individual control events.
However, if the user doesn't know what to enter, all you can
do is pop up a warning. If the "doen't know" scenario is
moderately common, users will quickly learn to ignore the
warning, rendering it useless.

I prefer to let users enter data in any order at any time
(even over several days). I provide a button that users can
click to say they think the quote/order/whatever is complete
and can be made "official". The button's Click event
procedure would the check all the required fields, generate
a message about the missing ones and skip the make it
official step.

If everthing checks out ok, then set a OfficialDate field to
Now() so you know the entry is complete (and maybe should
not be changed anymore).
 

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