[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 227
  • 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.
CallCentre.mdb
0
Everwulf
Asked:
Everwulf
  • 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
fldValidated=true
for each ctl in me.controls
   if ctl.tag="REQ" then
       if isnull(ctl) then
          fldValidated=false
          exit function
       end if
  end if
next

end function
0
 
Nick67Commented:
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.

But...IT"S BULLETPROOF
Users can't create or alter records without jumping through your hoops.
And that makes it worth the effort
0
 
EverwulfAuthor Commented:
Capricorn1,

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.

Nick,
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.
0
 
Nick67Commented:
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.
0
 
EverwulfAuthor Commented:
Is there any special I would need to do for a cancel button using Validation.
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

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