Search code examples
vbams-accesscontinuous-forms

MS Access continuous form bound checkbox


I have a situation where i need to set only one ID as default on a continuous form. It does not seem to be easy to do so. Pls have a look on attached image, it is allowing me to choose more than one. I have tried with radio button, it does not work either

sample


Solution

  • You can loop the RecordsetClone of the form:

    Private Sub IsDefault_AfterUpdate()
    
        Dim rs  As DAO.Recordset
        
        If Me.Dirty Then
            Me.Dirty = False
        End If
        
        If Me!IsDefault.Value = True Then
            ' Deselect other records.
            Set rs = Me.RecordsetClone
            rs.MoveFirst
            While Not rs.EOF
                If rs!Id.Value <> Me!Id.Value Then
                    If rs!IsDefault.Value = True Then
                        rs.Edit
                            rs!IsDefault.Value = False
                        rs.Update
                    End If
                End If
                rs.MoveNext
            Wend
            rs.Close
            
            Me!SomeOtherControl.SetFocus
            Me!IsDefault.Enabled = False
            Me!IsDefault.Locked = True
        End If
        
    End Sub
    
    Private Sub Form_Current()
    
        Dim Ready           As Boolean
        Dim NewRecord       As Boolean
        
        NewRecord = Me.NewRecord
        
        If NewRecord Then
            Me!IsDefault.DefaultValue = Not CBool(Me.RecordsetClone.RecordCount)
            Me!SomeOtherControl.SetFocus
        Else
            Ready = Not Me!IsDefault.Value
        End If
        
        ' The selected record cannot be deselected.
        ' Deselect by selecting another record.
        Me!IsDefault.Enabled = Ready
        Me!IsDefault.Locked = Not Ready
        
    End Sub