UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Multi Item Form Checkbox Selection, Access 2016    
 
   
lalit81
post May 22 2020, 08:21 AM
Post#1



Posts: 1
Joined: 22-May 20



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)
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

This post has been edited by lalit81: May 22 2020, 08:37 AM
Attached File(s)
Attached File  1590129596102.png ( 216.61K )Number of downloads: 11
 
Go to the top of the page
 
GroverParkGeorge
post May 22 2020, 08:35 AM
Post#2


UA Admin
Posts: 37,432
Joined: 20-June 02
From: Newcastle, WA


Welcome to UtterAccess.

Two questions need to be addressed.

First, ALL data is stored in tables. Therefore, we need to see the table to which this form is bound as well as the form itself. How is the table structured?

Second, I am assuming that the form is, in fact, bound to the table. Is it?

It looks to me as if you've created a continuous view form, but that checkbox control on it is not bound to a field in the table to which the form is bound. If that is the case, then you need to invest a bit of study into how continuous view forms work (as well as datasheet view forms).

Specifically, only one record at a time can have the focus in a continuous view form, although you can SEE other records. However, only BOUND controls will be able to reflect the value of the record. In this case, I suspect your check box is not bound to any field and therefore it will always show the same thing for all records.

Depending on what your goal is, there are probably viable ways to get there. I guess that's a third question. What is the goal?

--------------------
My Real Name Is George. Grover Park Consulting is where I did business for 20 years.
How to Ask a Good Question
Beginning SQL Server
Go to the top of the page
 
projecttoday
post May 22 2020, 09:41 AM
Post#3


UtterAccess VIP
Posts: 12,368
Joined: 10-February 04
From: South Charleston, WV


A option button does this automatically. Please provide more information. There may be a better approach to satisfying the requirements.

--------------------
Robert Crouser
Go to the top of the page
 
vanzie
post May 24 2020, 03:23 AM
Post#4



Posts: 32
Joined: 29-January 19



I'm sure there is an easier workaround but I haven't found any yet. I usually do this:

On the on click event of a checkbox:

me.chkbox1=1
me.chkbox2=0
me.chkbox3=0
me.chkbox4=0

Same as when I click chkbox2 the other checkboxes go to 0 e.g.

me.chkbox1=0
me.chkbox2=1
me.chkbox3=0
me.chkbox4=0

But for continuous forms I'm not sure if that will work

If someone has an easier method I would like to know
This post has been edited by vanzie: May 24 2020, 03:24 AM
Go to the top of the page
 
projecttoday
post May 24 2020, 06:47 AM
Post#5


UtterAccess VIP
Posts: 12,368
Joined: 10-February 04
From: South Charleston, WV


If you want to clear all the checkboxes on a form loop through the form's recordset, not the form's controls. You want to set the field, not the control.

--------------------
Robert Crouser
Go to the top of the page
 
projecttoday
post May 24 2020, 06:59 AM
Post#6


UtterAccess VIP
Posts: 12,368
Joined: 10-February 04
From: South Charleston, WV


The code will look something like this:

dim rs as dao.recordsetclone
rs.movefirst
do while not rs.eof
rs.chkbox = 0
rs.movenext
loop
set rs=nothing


--------------------
Robert Crouser
Go to the top of the page
 
projecttoday
post May 24 2020, 07:01 AM
Post#7


UtterAccess VIP
Posts: 12,368
Joined: 10-February 04
From: South Charleston, WV


You didn't provide a lot of information but an option button is for a single record for something like gender which can be male or female but not both. So maybe that won't work here.

--------------------
Robert Crouser
Go to the top of the page
 
tina t
post May 24 2020, 10:28 AM
Post#8



Posts: 6,664
Joined: 11-November 10
From: SoCal, USA


@vanzie,

it's all about context. if your form has 4 unbound checkbox controls, then i'd say yes, it would be much easier to use an option group as Robert mentioned.

if you have four bound checkbox controls, each to a separate field, then presumably you have four Yes/No (True/False) fields in the table underlying the form. then i'd say you should revisit the table design - multiple True/False fields is a flag for a non-normalized design.

and btw, the code you posted, while not the most efficient method (see first paragraph above), will work the same in ContinuousForms view as it does in SingleForm view. the difference is that anything you do to an unbound control will show up in every visible record in the form, as George mentioned, not just the record you're working on.

hth
tina

--------------------
"the wheel never stops turning"
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    2nd July 2020 - 06:35 AM