Multi Item Form checkbox Selection (1 Viewer)

lalit81inin

New member
Local time
Today, 16:32
Joined
May 22, 2020
Messages
8
I had created a multi item Form with the table as shown having a checkboxes .But If I select the checkbox all other chekcboxes should get clear only one can remain checked at a time. the form is shown below and code as well i dont want to use update query or for loop is there any way
Code:
Private Sub chk_Click()
If chk.Value = -1 Then
MsgBox (ID)
Dim s As String
'MsgBox (chk.name)

MsgBox (chk.name & "sdfjshfdjds")
Dim contr As Control
For Each contr In Me.Controls

    If TypeName(contr) = "CheckBox" Then
    
        contr.Value = False
      If contr.name = s Then
              contr.Value = True
    End If
     End If
Next
End If
End Sub
 

Attachments

  • 1590129596102.png
    1590129596102.png
    216.6 KB · Views: 95

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:02
Joined
May 7, 2009
Messages
19,233
the checkbox is unbound and your form is continuous.
on continuous form there is only but 1 checkbox (see it in design view).

what you will need to Include a Record is instead of checkbox, use
command button (cmdCheck) and an Unbound Textbox (txtUnbound).

in design view of your form, remove the checkbox.
put the command button on same position as the checkbox.
put txtUnbound anywhere, set it's Visible property=No.

add code to cmdCheck's Click event.
Code:
Private Sub cmdCheck_Click()
If Me.NewRecord = False Then
    If Instr(Me!txtUnbound, Me!ID & ",") > 0 Then
        Me!txtUnbound = Replace(Me!txtUnbound, Me!ID & ",", "")
    Else
        Me!txtUnbound = Me!txtUnbound & Me!ID & ","
    End If
End If
End Sub

the last step.
select together ID, Name and Age textbox.
add Conditional Format.

Expression Is= Nz([ID], 0) > 0 AND Instr([txtUnbound], [ID] & ",") > 0
choose different Backcolor (yellow, maybe).
 
Last edited:

lalit81inin

New member
Local time
Today, 16:32
Joined
May 22, 2020
Messages
8
the checkbox is unbound and your form is continuous.
on continuous form there is only but 1 checkbox (see it in design view).

what you will need to Include a Record is instead of checkbox, use
command button (cmdCheck) and an Unbound Textbox (txtUnbound).

in design view of your form, remove the checkbox.
put the command button on same position as the checkbox.
put txtUnbound anywhere, set it's Visible property=No.

add code to cmdCheck's Click event.
Code:
Private Sub cmdCheck_Click()
If Me.NewRecord = False Then
    If Instr(Me!txtUnbound, Me!ID & ",") > 0 Then
        Me!txtUnbound = Replace(Me!txtUnbound, Me!ID & ",", "")
    Else
        Me!txtUnbound = Me!txtUnbound & Me!ID & ","
    End If
End If
End Sub

the last step.
select together ID, Name and Age textbox.
add Conditional Format.

Expression Is= Nz([ID], 0) > 0 AND Instr([txtUnbound], [ID] & ",") > 0
choose different Backcolor (yellow, maybe).
Dear Friend Thanks For Your inpouts but as per the requirement there i need to use checkboxes only command button not permitted
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:02
Joined
May 7, 2009
Messages
19,233
you add a checkbox to your table.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:02
Joined
May 7, 2009
Messages
19,233
you just add the check field to your form.
on msa menu, Design, on Ribbon->Add Existing Fields.

I see your code.

Code:
Private Sub chk_Click()
If chk.Value = -1 Then
me.dirty=false
MsgBox (ID)

'MsgBox (chk.name)
currentdb.Execute "update table1 set check=0 where id <> " & me![id]
End If
End Sub
 
Last edited:

lalit81inin

New member
Local time
Today, 16:32
Joined
May 22, 2020
Messages
8
you just add the check field to your form.
on msa menu, Design, on Ribbon->Add Existing Fields.
Checked That but still problem persist it is keeping previousl;y heckbox checked as well my condition is when say id1 is already selected and after that i slect the ID 4 id 1 checkbox should get cleared
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:02
Joined
May 7, 2009
Messages
19,233
see my Edited post#6 for the code.
 

lalit81inin

New member
Local time
Today, 16:32
Joined
May 22, 2020
Messages
8
see my Edited post#6 for the code.
Dear Thanks for Your Efforts but the data is going to be more than 50,000 records using update commnd will affect the things and i already mention in my POST dont want to use UPDATE command
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:02
Joined
May 7, 2009
Messages
19,233
update query is Faster than using Loop.
I also saw your post "don't want to use update and loop".
 

Users who are viewing this thread

Top Bottom