PDA

View Full Version : How to stop a record being added



swain90
01-09-2009, 02:08 PM
When i fill in pieces of information on my form it checks each input box to see if information has been entered. (This is done by using a simple IF statement) This works it alerts me if there is a text box which has no data in it, but it still adds the record to the database which i don't want it to do.

Could you please help me with stopping it adding the records to the database with blank fields please :)


Cheers
Chris

Oorang
01-09-2009, 03:32 PM
Sure, there are several ways you can go. The least painful would be to open the table in design view, make the field required. And not allow Zero Length Strings.

CreganTur
01-09-2009, 07:56 PM
Welcome to the forum- always good to see new members!

Oorang's suggestion is excellent for ensuring that something is entered into the fields that you absolutely require your Users to provide input for.

Now, if you need to be more specific, then the best thing to do is to build some validation code using VBA.

I am assuming that your form has some sort of Submit button. If it does, then when the user clicks submit, the first block(s) of code that would run would be validation. They would look at the value of every field you define. By using conditionals (If statements, Select Case statements) you can check what the user input against your defined lists of what is acceptable. That way you can reject anything that you don't want.

If you do not have a submit button, then you can put your validation behind each object you want to validate. I suggest using either one of their focus events or the After Update event

If your fom is only for data input, then you need to set the form as an input form. You do this by bringing up the form's data properties. Look for the Data Entry property and set it to Yes or True. This makes it so the form is on;y for data entry- it doesn't show exisitng records in the table. It's great for keeping the Users from overriding existing records.

swain90
01-10-2009, 05:05 AM
Thanks for the help guys much appriciated i shall edit my database this afternoon and let you know if it works :cloud9: