• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 230
  • Last Modified:

How you code a form to valadate form fields to prevent the creation of a record.

I have a database that I need to prevent the auto-record creation. I have looked online and there seems to be two methods. Method one is using an unbound form which sounds more of a headache than what I am looking for. The other is validating the fields in the form which sounds much easier so I am looking in that direction.

Couple things to mention:

The form (frmCalls) which can be launched from the New Call or Update Call buttons contains a sub-form which will also need to be validated.

I will be adding a cancel button to abort the record but it is not there yet.

Due to the importance of this database all fields on this form and subform need to be validated.

Is there a simple code to do this or will I be writing code for each field.
  • 2
  • 2
1 Solution
Rey Obrero (Capricorn1)Commented:
you normally do validation of fields in the BeforeUpdate event of the form/subform

<Is there a simple code to do this or will I be writing code for each field.>
 * you can use the Tag property of the controls that you want validated, by placing a value in the Tag property, say REQ

you can write a sub or function to do the validation, something like this

function fldValidated() as boolean
dim ctl as control
for each ctl in me.controls
   if ctl.tag="REQ" then
       if isnull(ctl) then
          exit function
       end if
  end if

end function
And unbound forms really aren't that much of a headache.
Create the bound form.
Select all the controls that are bound
Put an empty space in the control source
Move to another property field
Go back to the control source and remove even the empty space
Done, everything is unbound.

Now you need to code some recordset stuff to populate the fields on load and current.
And code some recordset stuff to validate and blow in records on a "Save this input" button click.

A lot of the structure of the code is the same.
It isn't that much work, because there can be a lot of copy and paste.

Users can't create or alter records without jumping through your hoops.
And that makes it worth the effort
EverwulfAuthor Commented:

So I would have to put a code similar to that in both the parent form and the sub form for both to be checked...correct?

I also want to have two buttons for them as well, the Complete button for when they are ready to save the record and a Cancel button for when they want to just quit and not make a record. Is there any special code for either that tells it to continue and create or disregarde and not create.

Thanks for the head up on unbound forms, Many other sites made it seem like pulling teeth. I might look into it for another project. So thanks.
One of the first forms I ever built was based on an un-updateable query...so I had no choices.
I've never looked back.
The inbound form solved that problem...but it was so superior in terms of user experience and preventing user FUBAR that I use them for anything that's fairly involved.
EverwulfAuthor Commented:
Is there any special I would need to do for a cancel button using Validation.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now