Hi SteveS,
Apologies if my previous postings appear slightly confusing...
All posting's starting with "Hi Steve" were directed at your good self
"SteveS", and it was only sometime later that I realised Steve from PC
datasheet.com believed they were directed at him. Yes I realise now that I
should have started with "Hi SteveS", I hope you accept that this was an
honest mistake.
Accordingly apologies Steve from PC datasheet.com if the phrasing of my
postings appeared somewhat teacher to pupil style, and therefore
potentially offensive to you as you obviously have considerable Access
knowledge, but they were directed at SteveS, and I was trying to keep it
simple, explaining not just the code, but the thought processes behind
developing an algorithm to achieve his objectives.
In regard to the solutions proposed... generally it is my experience that
for this type of feature the number of records involved is limited (< 50)
because you wouldn't expect the user to wade through a list of
100's/1000's of records, making a decision about the status of each and
everyone of them on a regular basis due to the increased margin for user
error.
If this is the case then I believe the first solution will be more than
adequate for your needs.
If this is not the case then I would consider rethinking the user
interface to reduce a potentially onerous and error prone user task
Perhaps by limiting and grouping the records in such away that the user
can quickly make a decision about their status and therefore use the
Select All/Deselect All feature.
Just my 2 cents worth.
Guy
Guy said:
In fact a few typo's in my example...
Depending on the structure of your data you may want to specify:
1) The foreign key (not the primary key)
2) No key to update all records in the table.
Forms!txtPrimary key should be me!txtPrimary key or something/nothing
else (see above)
and also
Set db = Nothing
Before exiting.
Cheers
Guy
Guy said:
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
(e-mail address removed)
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!