Field validation

  • Thread starter D M via AccessMonster.com
  • Start date
D

D M via AccessMonster.com

Access 2003 Front end - SQL 2000 Back end

I have set up a Validation rule for each field in the subform property - len
([field-name]) >0 (testing to see that some data is input )
When creating a new record, I can tab over the fields without any validation
text message being triggered. What Is the solution to this problem?
 
N

Naresh Nichani

Validation Rule is checked if you type something.

You can do this with VBA code if you need feedback on every field when
tabbed.

Easier solution is to set Required to True for field and it will check when
record is saved to database.

Regards,

Naresh Nichani
Microsoft Access MVP
 
G

Guest

A Validation rule is not checked until something is entered in the field.
Also, the value of a text box that has had nothing entered is Null. It will
not evaluate as a length of 0, it will return Null instead of a length. A
better technique is to use code in the Before Update event of the control
that checks for data and provides meaningful user feedback.

If Len(Trim(Nz(Me.SomeField,""))) = 0 then 'Checks for both Null and a
length of 0
Cancel = True
MsgBox "Data Required for this Field"
End If
 
T

Tim Ferguson

A
better technique is to use code in the Before Update event of the
control that checks for data and provides meaningful user feedback.

The BeforeUpdate also depends on the data being changed.

The Exit event always fires (as long as the user actually entered the
control at all), and also has a Cancel parameter that can be set to True to
prevent the user moving on, and also allows you to change the contents of
the control.

HTH


Tim F
 
G

Guest

You are correct; however, putting it in the Exit event can cause its own set
of problems. If no data is entered and you want to close the form or cancel
the update, you can't get out of the control. Perhaps the Before Update
event of the form would be better.
 
T

Tim Ferguson

You are correct; however, putting it in the Exit event can cause its
own set of problems. If no data is entered and you want to close the
form or cancel the update, you can't get out of the control. Perhaps
the Before Update event of the form would be better.

.... which leads us back to the OP problem, that the user can tab past his
control and leave it empty.

One thing nobody has yet suggested is putting in a sensible default
value, so that it's not empty to begin with.

All the best


Tim F
 

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