Validation rules

Aleni

Registered User.
Local time
Today, 09:54
Joined
Dec 6, 2012
Messages
45
Hi everyone!

I have a from to enter new data in a table but i want to use validation rules to not to except blank records.

I tried this code:
if txtItem="" then
msgbox("Please fill the required fields")
else
code to insert new data
end if

It is not working. My form is accepting the blank records.

What is the correct code?


thank you
 
The ValidationRule must be an expression not a full procedure.

ValidationText is where you put the message to be displayed if the expression returns False.

Many developers prefer to call a procedure on the BeforeUpdate event of the form or the AfterUpdate Event of the control. This give a lot more abilty to configure what happens and is what you are trying to do.
 
thank you but
How would i code the validation rule or is their any other way for this validation rule?
How do i make my form not to accept the blank records.
thank you...
 
Put this in the Validation Rule. It checks for Null and Zero Length String.

Len([txtItem] & "") <> 0

However if instead you put something like the code you originally wrote into the BeforeUpdate Event of the Form then it will allow you to better control exactly what happens when the the user has not filled in the textbox.
 
thank you but
How would i code the validation rule or is their any other way for this validation rule?
How do i make my form not to accept the blank records.
thank you...

I think you mean blank fields. You can set "allow zero length string" or "Required" to "No" in the table design for that field.

HTH
 
Thank you Galaxiom and joemach,
I tried both of your suggestions but its not working.
I even tried to put my code into the BeforeUpdate Event of the Form but its of no use.

Is there any other way?
thank you.
 
Last edited:
Thank you Galaxiom and joemach,
I tried both of your suggestions but its not working.
I even tried to put my code into the BeforeUpdate Event of the Form but its of no use.

thank you.

That's odd. It works for me. What version of Access are you using?

My preference would be to add code to the Before Update event of the Form and not let the user leave that control until it was filled in.

Let us know if you need an more help.
 
Last edited:
I am using Access 2007
And I have add code to the Before Update event of the Form still its not working.
Its an unbound form.
thank you...

Hi everyone!
I found the solution.

If IsNull(txtItem)

I used this code and now it's working fine.
thank you every one.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom