Control validation...when should you do it?

  • Thread starter Thread starter True.Kilted.Scot
  • Start date Start date
T

True.Kilted.Scot

I have a form with several controls on it, recording text, dates and
times.

The date control should not hold a date that is earlier than any date
already recorded in the database. The second time control--end
time--cannot be earlier than the time entered in the first time
control--start time.

My question...should the validation for each of these controls be
performed in the BeforeUpdate event of each of the controls, or in the
BeforeUpdate event of the form itself?

Many thanks

Duncan
 
I have a form with several controls on it, recording text, dates and
times.

The date control should not hold a date that is earlier than any date
already recorded in the database. The second time control--end
time--cannot be earlier than the time entered in the first time
control--start time.

My question...should the validation for each of these controls be
performed in the BeforeUpdate event of each of the controls, or in the
BeforeUpdate event of the form itself?

Many thanks

Duncan

Figured one Duncan should reply to another.

*should* really matters for your UI. You can check for the value in
either place, but it's a matter of when (and how) you want to tell the
user the data is invalid. If you do it on the control, you stop it
before they move onto the next piece. If you wait until the form, then
you summarize all the things that are wrong at one time, and give them a
single message.

I personally like to do it on the control level, but I've got at least
one application that does it on the form. It's really a workflow issue
for you to decide.
 
You have 2 issues here.

The first is comparing the StartDate to the StartDate of every other record.
You could use the BeforeUpdate event of the control if you wish.

The second issue involves comparing 2 fields. You do not know the order that
the user will enter the controls, and you also want to let the user switch
back and forth until the entry is as they want, so you want the BeforeUpdate
event of the form, not the control.

An even better idea would be to put a validation rule on the table instead
of using Form_BeforeUpdate. In table design view, the table's validation
rule is in the Properties box. The rule would be:
[StartDate] <= [EndDate]

In some versions of Access, that will have the effect of making the fields
required, so you might prefer to use the rule:
([StartDate] Is Null) OR ([EndDate] Is Null) OR ([StartDate] <=
[EndDate])
 

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

Back
Top