Solved

After validation, make checkbox field true

Posted on 2008-10-17
3
194 Views
Last Modified: 2013-11-28
This validation code works fine, but I forgot to ask (this comes from a previous question):

I want to validate three textboxes, one combo box and 6 checkbox fields. This code does this fine, but now I need to mark another checkbox field IF all required fields are filled or marked AND AFTER that validation.

I've tried adding this line

Me.CheckBoxField = -1

between the For Next statements and between the IF statements, but when it goes thru the validation, it marks the field, EVEN if the fields are not filled or marked.
Private Sub abtnCommand1_Click()
 
Dim ctl As Control
 
For Each ctl In Me.Controls
    If ctl.Tag = "Req" Then
        If ctl.ControlType = acCheckBox Then
            If IsNull(ctl.Value) Or ctl.Value = 0 Then
                MsgBox "Required fields missing. Fill or check missing fields", vbCritical, "Missing fields"
                ctl.SetFocus
                Exit For
            End If
        Else
            If IsNull(ctl) Then
                MsgBox "Required fields missing. Fill or check missing fields", vbCritical, "Missing fields"
                ctl.BackColor = vbYellow
                Exit For
            End If
        End If
    End If
    
Next
 
Exit Sub
 
End Sub

Open in new window

0
Comment
Question by:richieac77
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 16

Accepted Solution

by:
Chuck Wood earned 65 total points
ID: 22741505
Try this;
Private Sub abtnCommand1_Click()
    Dim ctl As Control, blnGood As Boolean
    blnGood = True
    For Each ctl In Me.Controls
        If ctl.Tag = "Req" Then
            If ctl.ControlType = acCheckBox Then
                If IsNull(ctl.Value) Or ctl.Value = 0 Then
                    MsgBox "Required fields missing. " & _
                       "Fill or check missing fields", vbCritical, "Missing fields"
                    ctl.SetFocus
                    blnGood = False
                    Exit For
                End If
            Else
                If IsNull(ctl) Then
                    MsgBox "Required fields missing. " & _
                        "Fill or check missing fields", vbCritical, "Missing fields"
                    ctl.BackColor = vbYellow
                    blnGood = False
                    Exit For
                End If
            End If
        End If
    Next
    If blnGood Then
        Me.CheckBoxField = True
    Else
        Me.CheckBoxField = False
    End If
End Sub

Open in new window

0
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 60 total points
ID: 22741518

Private Sub abtnCommand1_Click()
dim blFilled as boolean 
Dim ctl As Control
blFilled=True 
For Each ctl In Me.Controls
    If ctl.Tag = "Req" Then
        If ctl.ControlType = acCheckBox Then
            If IsNull(ctl.Value) Or ctl.Value = 0 Then
                blFilled=false
                MsgBox "Required fields missing. Fill or check missing fields", vbCritical, "Missing fields"
                ctl.SetFocus
                Exit For
            End If
        Else
            If IsNull(ctl) Then
                blFilled=false
                MsgBox "Required fields missing. Fill or check missing fields", vbCritical, "Missing fields"
                ctl.BackColor = vbYellow
                Exit For
            End If
        End If
    End If
    
Next
 
Exit Sub
Me.CheckBoxField = blFilled
End Sub

Open in new window

0
 

Author Closing Comment

by:richieac77
ID: 31507161
Thanks for the prompt response!!!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

756 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