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

Posted on 2011-04-21
Last Modified: 2012-05-11
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.
Question by:Everwulf
    LVL 119

    Accepted Solution

    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
    LVL 26

    Expert Comment

    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

    Author Comment


    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.
    LVL 26

    Expert Comment

    One of the first forms I ever built was based on an un-updateable 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.

    Author Comment

    Is there any special I would need to do for a cancel button using Validation.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
    I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
    Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
    Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now