Atleast one entry required

renenger

Registered User.
Local time
Yesterday, 17:00
Joined
Oct 25, 2002
Messages
117
I have a form with alot of checkboxes. Users enter problems found on job inspection. I have added a checkbox called NoProblems. If there are no problems found, that box should be checked. When the user submits the information, I need to form to see if any of those boxes are checked, if not then the NoProblems checkbox should be checked.

So users have to check atleast one problem or the no problem. Is there an easier way to do this than add code for each checkbox?
 
Try this out -

In the tag property of each of the text boxes type something like NC

Then, use this code in the BeforeUpdate event of the form:

Code:
Dim ctl As Control
Dim blnCheck As Boolean

For Each ctl in Me.Controls
  If ctl.Tag = "NC" Then
      If ctl = True Then
         blnCheck = True
      End If
  Next ctl
  If blnCheck = False Then
      Me.NoProblems = True
  End If

This will check to see if any are checked and if so it will set the boolean flag. If it remains false then there aren't any boxes checked and it will automatically check the NoProblems checkbox.

You could modify it so it would generate a message that there aren't problems and for them to verify that is correct and if so it will check the box and if not you can use Cancel = True to cancel the form update so they can fix it.
 

Users who are viewing this thread

Back
Top Bottom