Access World Forums

Access World Forums (https://www.access-programmers.co.uk/forums/index.php)
-   Forms (https://www.access-programmers.co.uk/forums/forumdisplay.php?f=9)
-   -   Select All Checkboxes in continuous subform (https://www.access-programmers.co.uk/forums/showthread.php?t=307819)

alvingenius 11-08-2019 12:05 PM

Select All Checkboxes in continuous subform
 
Hello


I've a main form Called "frm_Main" and i'm using it as Form Heading to filter records in subforms in Navigation form
all subforms view as continuous form
this subform is getting data from a query based on filters i use in main form

so in this main form i wanna create checkbox field or button to "select all" all checkboxes in the filtered subform records ( table have yes/no field )

NauticalGent 11-08-2019 12:12 PM

Re: Select All Checkboxes in continuous subform
 
On the main form's control (either checkbox or button) you will need to have code on the applicable event (checkbox = AfterUpdate / Button = OnClick) that loops through the controls on the subform and if it is a checkbox, then makes the value = true.

alvingenius 11-08-2019 12:15 PM

Re: Select All Checkboxes in continuous subform
 
Quote:

Originally Posted by NauticalGent (Post 1649740)
On the main form's control (either checkbox or button) you will need to have code on the applicable event (checkbox = AfterUpdate / Button = OnClick) that loops through the controls on the subform and if it is a checkbox, then makes the value = true.

yeah that's what i need , so do u have a code for it ?

NauticalGent 11-08-2019 12:18 PM

Re: Select All Checkboxes in continuous subform
 
I can give it a shot, but you will need to make a decision on what you want on your main form first...

theDBguy 11-08-2019 12:20 PM

Re: Select All Checkboxes in continuous subform
 
Hi. Another option might be to simply update the underlying table to check the box. For example:
Code:

UPDATE TableName SET CheckboxField=True WHERE YourCriteriaHere
You can then Requery the form to display the updated data.
Hope it helps...

alvingenius 11-08-2019 12:20 PM

Re: Select All Checkboxes in continuous subform
 
it will be a button click
so when i click it it will select all checkboxes in filtered records in subform

and i don't want to deselect

alvingenius 11-08-2019 12:21 PM

Re: Select All Checkboxes in continuous subform
 
Quote:

Originally Posted by theDBguy (Post 1649743)
Hi. Another option might be to simply update the underlying table to check the box. For example:
Code:

UPDATE TableName SET CheckboxField=True WHERE YourCriteriaHere
You can then Requery the form to display the updated data.
Hope it helps...

Can't do it in a simple update query as filters is not the same everytime
so i've to do that on the fly on the showed records

NauticalGent 11-08-2019 12:24 PM

Re: Select All Checkboxes in continuous subform
 
All yours DBG, it's getting late here...

theDBguy 11-08-2019 12:26 PM

Re: Select All Checkboxes in continuous subform
 
Quote:

Originally Posted by NauticalGent (Post 1649748)
All yours DBG, it's getting late here...

Thanks! Ciao!

theDBguy 11-08-2019 12:26 PM

Re: Select All Checkboxes in continuous subform
 
Quote:

Originally Posted by alvingenius (Post 1649746)
Can't do it in a simple update query as filters is not the same everytime
so i've to do that on the fly on the showed records

I think it can because you "know" the criteria every time it gets changed. For example, how do you modify what's displayed on the form after a criteria is selected?

alvingenius 11-08-2019 12:29 PM

Re: Select All Checkboxes in continuous subform
 
in the main form i'm using 3 combo boxes to filter subform records and my choices not the same everytime so i can't use update query as i'm using different criteria everytime

isladogs 11-08-2019 12:29 PM

Re: Select All Checkboxes in continuous subform
 
If you already have a yes/no field to which your checkbox is bound then an update sql statement is definitely the best solution. You can build the filter dynamically to work with different criteria each time and set the field true ....then set to false afterwards if you wish

Or if you don't have a suitable field add one and call it something like Tag.
Its purpose is purely to mark a group of records matching a particular set of filter criteria so you can do something with those records.

Micron 11-08-2019 12:31 PM

Re: Select All Checkboxes in continuous subform
 
If the field is bound to a table or query that is updatable, then something like
Code:

Private Sub chkAll_Click()
Dim rs As DAO.Recordset

Set rs = Me.RecordsetClone
Do Until rs.EOF
  With  rs
    .Edit
    .Fields("nameOf Field") = True
    .Update
    .MoveNext
 Loop
set rs = Nothing

 
End Sub

You will have to replace Me with a valid subform reference, which I didn't attempt because you didn't provide the names of the other forms. Also, if this is a subform on a navigation form you would need the correct subform reference. Your form design isn't clear to me so if you need help with the reference, post back but do clarify if this is a subform on a navigation form or what.

alvingenius 11-08-2019 12:32 PM

Re: Select All Checkboxes in continuous subform
 
i've found this code
Code:

Private Sub cmdTickAllBoxes_Click()

Dim rs As DAO.Recordset

Set rs = Me.RecordsetClone

 With rs
 
  .MoveFirst
 
 Do While Not rs.EOF
  .Edit
  !CheckboxFieldName = -1
  .Update
  .MoveNext
 Loop

End With

rs.Close

Set rs = Nothing

Me.Requery

End Sub

and i tried with button in subform it self and it worked

but how to move this code to the main form?
how to point to " !CheckboxFieldName"
as this Checkbox Field is in subform in navigation form named "NavigationSubform" in main form named "frm_main"

theDBguy 11-08-2019 12:37 PM

Re: Select All Checkboxes in continuous subform
 
Hi. You could try changing this line:
Code:

Set rs = Me.RecordsetClone
into something like this:
Code:

Set rs = Me.SubformControlName.Form.RecordsetClone
However, I still say an UPDATE query will still work, but that could be a discussion for another day.


All times are GMT -8. The time now is 11:43 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World