Validating user input

browninaz

Ugly Data Hoarder
Local time
Today, 13:54
Joined
Oct 26, 2012
Messages
88
Hello everyone,

I have two check box controls on a form, and I would like to set some sort of validation rule to make sure that one of the boxes is checked before the form is closed. I also have many other forms with text, radio, etc. controls that I would also like to set the same rule for. Can someone please give me a quick answer?

Thanks in advance, and I hope your having a good day.
 
a few quick thoughts and questions . . .
do you need to run this check before the user moves to a new record or just when the form closes? is there a default value? do you need the user to choose one or can you calculate a good prediction based on past data?
 
Validation to insure that a given Control is populated is usually done with code in the Form_BeforeUpdate event; notice that this is the Form's BeforeUpdate event. Checking for population in any of the Control's events is useless, because the user can simply not enter the Control and the Validation attempt will never be executed! Here's some pretty standard code for doing this.

Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)

 If Nz(Me.Control1,"") = "" Then
   MsgBox "Control1 Must Not Be Left Blank!"
   Cancel = True
   Control1.SetFocus
   Exit Sub
 End If
 
If Nz(Me.Control2, "") = "" Then
   MsgBox "Control2 Must Not Be Left Blank!"
   Cancel = True
   Control2.SetFocus
   Exit Sub
 End If

End Sub
If you were talking about a large number of Controls, you could 'Tag' those on a Form that need to be checked and then loop through all the Controls, checking the 'tagged' ones for population. But if it's only a few I usually go ahead and do them individually, as above.

Linq ;0)>
 
If the rqiurement that one and only one of the two checkboxes is ticked then the data structure is not properly normalized.

If it is the case that one or both can be ticked then that is OK.
 
Thanks to all for the input...

To lagbolt,
Yes I would like this to run before the user moves to a new record, no, there is no default value, and yes, I need the user to choose one or both to save the record or the input will not be recorded to the tables and the form crashes.

To missinglinq,
Please, no code yet. I'm just getting my feet wet with VBA and SQL. Thanks for the help though. Theres got to be a way to do it without for now.

To Galaxiom,
One or both can be ticked...

Because I am still so new at this, I am still having a hard time understanding the logic of my database sometimes. I don't develop for a living, I run a retail business, and finding the time to do what I love (programming) is hard to come by. Access is a fantastic program, and someday my database will be perfect, but until then, I have you guys (and gals).
 

Users who are viewing this thread

Back
Top Bottom