Required Data Entry

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Currently I have my code written so that if a field is left empty a message appears telling the user that they must fill in the field. The "requirement" comes from the on exit sub procedure.

The first five fields are "required" to be filled. The user can not go back and correct a mistake until the first five fields have been filled in. ie User is on answer four and they find out they made a mistake on answer two. The user must complete the five answers before entering control tab to go backward and correct mistakes

Is there some way that this can be overwritten on a temporary basis

I appreciate your help

Kenny
 
Kenny G said:
Currently I have my code written so that if a field is left empty a
message appears telling the user that they must fill in the field. The
"requirement" comes from the on exit sub procedure.
The first five fields are "required" to be filled. The user can not go
back and correct a mistake until the first five fields have been filled in.
ie User is on answer four and they find out they made a mistake on answer
two. The user must complete the five answers before entering control tab
to go backward and correct mistakes.
Is there some way that this can be overwritten on a temporary basis?

I would put this sort of validation in the BeforeUpdate of the form rather
than OnExit of the controls. What if a required control never gets focus
in the first place? In the BeforeUpdate of the form you can test all of
the fields and display a single message indicating all of the problems.
 
Rick

Thanks for your reply

That's a great idea. Do I take each of those and put them on the before update in a Case If sub
If I have a message indicating there are some fields that need data entry - would it be possible to
have the field turn red until the requirement is fulfilled

Thanks, Ken
 
Kenny G said:
Rick,

Thanks for your reply.

That's a great idea. Do I take each of those and put them on the before update in a Case If sub?
If I have a message indicating there are some fields that need data
entry - would it be possible to
have the field turn red until the requirement is fulfilled?

You can either have a series of If-Then blocks and produce a Message for
each validation failure individually or (my preference) you can accumulate
the problems and display a single message. Here is a sample of how I do
that.

Dim RqdMsg as string

RqdMsg = "The Following Required Fields Were Left Blank."
'(initially this variable has text that is 46 characters long)

If IsNull(RequiredField1) Then RqdMsg = RqdMsg & vbcrlf & "Field1"
If IsNull(RequiredField2) Then RqdMsg = RqdMsg & vbcrlf & "Field2"
'repeat as necessary

If Len(RqdMsg) > 46 Then
MsgBox RqdMsg
Cancel = True
End if

During the sequence of If-Thens you certainly could add code that changed
the color of the control if you want.
 
Rick,

Thanks for you prompt reply, I'll try this first thing in the morning

The more I know, the more I realize I don't know

Thanks Again, Kenny G
 
Back
Top