Solved

After validation, make checkbox field true

Posted on 2008-10-17
3
191 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
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 119

Assisted Solution

by:Rey Obrero
Rey Obrero 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
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 …

910 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

23 Experts available now in Live!

Get 1:1 Help Now