Steve,
There are many ways to skin the cat.
If you believe performance will be a factor, then here is an alternative
solution using a parameterised Update query.
Private Sub cmdSelect_Click()
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Static blnSelect As Boolean
' Toggle select/deselect all
blnSelect = Not blnSelect
Set db = CurrentDb
Set qdf = db.QueryDefs("qupdSelectAll")
qdf.Parameters("PrimaryKey") = Forms!txtPrimaryKey ' Note. may require
more parameters if a composite key.
qdf.Parameters("Status") = blnSelect
qdf.Execute
Set qdf = Nothing
Me.Refresh
End Sub
As you can see the basic design has changed only the method of updating
the records.
Hope this helps
Guy
Yes, looks like it should work. However, an Update query is much faster
than cycling through a recordset!
PC Datasheet
Providing Customers A Resource For Help With Access, Excel And Word
Applications
[email protected]
Steve,
This is a quick example that should work, although I haven't tested
it. Each time the users clicks the button it will either select or
deselect all your records. Note. the gotcha with this code is that you
will undoubtedly need to set the initial select status of blnSelect to
the correct value based on your current recordset value(s) before the
user clicks the button.
Otherwise the first time the user clicks the button it will select all
(when all records may have already been selected). In which case
remove the Static blnSelect, perhaps making it a module level variable
that you set somewhere, the Form_Current event may be appropriate.
Private Sub cmdSelect_Click()
Dim rst As New DAO.Recordset
Static blnSelect As Boolean
' Toggle select/deselect all
blnSelect = Not blnSelect
Set rst = Me.RecordsetClone
' Update status
With rst
While Not .EOF
!Status = blnSelect
.Update
.MoveNext
Wend
.Close
End With
Set rst = Nothing
Me.Refresh
End Sub
Hope this helps.
Cheers
Guy
:
Hi all,
I have a continuous form which users can input the name of an
activity and
select or de-select an associated checkbox depending on whether
they want
that activity counted in a separate report or not. I would like to
add
"Select All" and "Deselect All" command buttons in the form
footer, which
will either check or uncheck all the associated checkboxes within
the
continuous form.
I've tried the following (rather simplistic) code for a "Select
All"
button,
but it only works on a single record (the last one that was
active).
Private Sub cmdSelectAll_Click()
Me.[chkboxTrackResults].Value = True
End Sub
I need to get this to work in all the records displayed on the
continuous
form. How can I do this (keeping in mind I'm relatively new to
Access...)
Thanks in advance!
One thing you could try is to use an SQL statement (in the Click
event) to
update the data in the underlying table, then re-query the form.
Carl Rapson
OK, but I will need some help with this approach. (Like I said, am
relatively new to Access, and am self-taught. Also, I've only done
minimal
work with SQL statements for queries, not with forms...)
1) Is this the same as the 'build event', or if not where do I go to
get
into SQL view from the properties of my control? (Or from wherever in
the
design view of my form)
2) My table is called tblAcitivities. So assume my code would need to
be
something like (need help with the parts in <>, which is most of
it...):
<what would the 'on click' code be?>
SELECT chkboxTrackResults FROM tblActivities
<what would the code be for "enable = true"?>
<code for re-query of form>
3) Would this update the settings for every record though?
Thanks!