Check box on continuous form

BWAT

Registered User.
Local time
Today, 18:34
Joined
Jan 18, 2008
Messages
11
Is there a way to loop through controls on a continuous form? On an exit command, I would like to see if any check boxes on a continuous subform are checked. I am running into the problem that if I select 2 boxes, and then deselect one....on exit the focus is on the de-selected box and it lets me exit. I have tried a few different things, but cant figure it out. Below is the code I used. Thanks for nay help in advance.

'Dim rsClone As Recordset
'Dim rsClone2 As Recordset
'Set rsClone = Forms![frmItemMaint]![subfrmOpenItems].Form.RecordsetClone
'Set rsClone2 = Forms![frmItemMaint]![subfrmClearedItems].Form.RecordsetClone

'If rsClone.RecordCount <> 0 Then
' If Forms![frmItemMaint]![subfrmOpenItems]!txtChkClr = True Then
' MsgBox "You Cannot Exit a Rec with Selected Pending or Unselected Cleared Items outstanding.", vbOKOnly
' Exit Sub
' End If
'End If

'If rsClone2.RecordCount <> 0 Then
' If Forms![frmItemMaint]![subfrmClearedItems]!txtChkClr = False Then
' MsgBox "You Cannot Exit a Rec with Selected Pending or Unselected Cleared Items outstanding.", vbOKOnly
' Exit Sub
' End If
'End If
'Set rsClone = Nothing
'Set rsClone2 = Nothing
 
Upon what event are you performing this checking?
Are are you wanting to check the values of the fields bound to checkboxes in every row of the subform?
 
There is a button to exit the main form. I need this to go behind that.
I am just looking for it to not allow the form to be closed if there are checkboxes checked.
 
Something vaguely like

Code:
    Dim ctl As Control
    
    With Me.Recordset.Clone
        Do Until .EOF
            For Each ctl In Me.Controls
                If ctl.ControlType = acCheckBox Then
                    If Len(ctl.ControlSource) > 0 Then
                        If .Fields(ctl.ControlSource) Then
                            MsgBox "A checkbox is checked"
                            Exit Do
                        End If
                    End If
                End If
            Next
            .MoveNext
        Loop
    End With

Could be made more efficient - but as a core concept it's there.
 
Thanks LPurivs...I will give that a go.
 

Users who are viewing this thread

Back
Top Bottom