Only Allow 1 Selection

fcmsb13

Registered User.
Local time
Today, 13:07
Joined
Nov 26, 2006
Messages
13
Hi I have a continuous form that has bound checkboxes next to each record. Right now the code below finds the records that are checked and edits them accordingly. I need to find a way to make only one checkbox be able to be checked at a time. Or have the code below find if 2 or more checkboxes are checked, then prompt and exit sub.
Code:
Private Sub Command43_Click()
Set rs = Me.Recordset
Dim user As DAO.Database
Set user = DAO.OpenDatabase("c:\a\user.mdb")
Set rs3 = user.OpenRecordset("currentuser", dbOpenDynaset)
rs.MoveFirst
Do While Not rs.EOF
rs.Edit
If rs!dispositionchk <> 0 Then
    rs!status = "Do Not Call" 'change status to to be contacted
    rs!dnc = "DNC"
    rs!lastlo = rs!Assignedto
    rs!Assignedto = " "  'assignedto=current employee name
    rs!LDdate = Now()
    rs!LDdisposition = "Do Not Call"
    rs.Update
    Set rsmyrs = CurrentDb.OpenRecordset("internetcalls", dbOpenDynaset) ' open table
    rsmyrs.Edit
    rsmyrs.addnew
    rsmyrs!ActivityDate = Now()
    rsmyrs!disposition = "Do Not Call"
    rsmyrs!LeadID = rs!LeadID
    rsmyrs!Employee = rs3!Username
    rsmyrs.Update
    Set rsmyrs = CurrentDb.OpenRecordset("call log", dbOpenDynaset) ' open table
    rsmyrs.Edit
    rsmyrs.addnew
    rsmyrs![Activity Date] = Now()
    rsmyrs!disposition = "Do Not Call"
    rsmyrs![Lead Id] = rs!LeadID
    rsmyrs!Employee = rs3!Username
    rsmyrs.Update
    rsmyrs.Close
End If
rs.MoveNext
Loop
Me.Requery
End Sub
 
You could add this function:

Code:
Public Function fMoreThanOne() As Boolean
fMoreThanOne = False
Dim rs As DAO.Recordset
' Set rs = DB.OpenRecordset(strSQL, dbOpenForwardOnly)
Set rs = Me.Recordset
Dim bytCountRec As Byte
Do Until rs.EOF
                If rs![dispositionchk] Then
                    bytCountRec = bytCountRec + 1
                        If bytCountRec > 1 Then
                            fMoreThanOne = True
                            Exit Function
                        End If
                End If
        rs.MoveNext
    Loop
    rs.Close
    Set rs = Nothing
End Function


And use it like this:

Code:
Private Sub Command43_Click()
If fMoreThanOne then Exit Sub
Set rs = Me.Recordset

I was interested in this problem because I have never seen this code used before:

Set rs = Me.Recordset

and I was interested to see what effect it had, I thought it was quite slow because it Scans through all of the records in the form. I would suggest replacing this with an SQL statement as I think it would be faster.

cheers Tony

PS:
Put your SQL in here where the strSQL is....
' Set rs = DB.OpenRecordset(strSQL, dbOpenForwardOnly)
 

Users who are viewing this thread

Back
Top Bottom