Re: modifying Kallal's Multiselect database example
- From: "Graham Mandeno" <Graham.Mandeno@xxxxxxxxxxxxx>
- Date: Thu, 28 Aug 2008 10:50:50 +1200
Hi Amanda
The following code will add every record in your current recordset to the
collection:
Private Function SelectAll()
' empty the collection
Set colCheckBox = Nothing
With Me.RecordsetClone
.MoveFirst
Do Until .EOF
colCheckBox.Add CLng(!ContactID), CStr(!ContactID)
.MoveNext
Loop
End With
Me.Check11.Requery
End Function
You will need to call this when the form first loads, and also whenever a
filter is applied.
The problem is that if you apply a filter using the user interface (the
Records menu or the toolbar or the right-click menu) then you need a way of
executing your code AFTER the filter has been applied. There is an
ApplyFilter event, but unfortunately this is fired BEFORE the filter is
applied.
However, after applying a filter or loading the form initially, one of the
first things that happens is that Form_Current is called for the first
record, so I've just tested this workaround and it seems to work OK.
Declare a module-level boolean variable:
Dim fCollectionInitialized As Boolean
In Form_ApplyFilter and BEFORE you apply a filter in any of your code, set
this variable to False.
In Form_Current, if the boolean is false then call SelectAll and set it to
True:
Private Sub Form_Current()
If Not fCollectionInitialized Then
SelectAll
fCollectionInitialized = True
End If
End Sub
--
Good Luck :-)
Graham Mandeno [Access MVP]
Auckland, New Zealand
"Amanda" <Amanda@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:E15297CC-1C81-4CC4-B841-69A8174217B9@xxxxxxxxxxxxxxxx
I used Albert Kallal's Multi Select example to create a continuous form
that
uses checkboxes to select specific records in an animal management
database.
(I work at a wildcat sanctuary)
So I incorporated Kallal's code into my form, but I am doing the opposite
operation. In Kallal's program, the record ID is added to a collection
every
time the checkbox for a record is clicked, and it is removed from the
collection when the checkbox is unclicked.
I want all the records checked to begin with, and then the user can
uncheck
the records. I can change the checkbox so that it initially displays as
checked, but the collection of all the checked values is still empty, so
if
you uncheck the box, you get an error- it can't remove a value that isn't
there.
The list of records is created from criteria that are selected from
unbound
checkboxes in the header (basically the Search Criteria tutorial from
Allen
Browne), so I have a strWhere variable with the criteria that creates the
continuous form part.
How can I populate the colCheckbox collection initially with all the
record
ID values?
Kallal's example database is at
http://www.members.shaw.ca/AlbertKallal/msaccess/msaccess.html
Thanks, Amanda
.
- References:
- modifying Kallal's Multiselect database example
- From: Amanda
- modifying Kallal's Multiselect database example
- Prev by Date: Re: Not In List 2 values
- Next by Date: Re: vbCrLf doesnt work in 2007 runtime, but works ok in the main app
- Previous by thread: modifying Kallal's Multiselect database example
- Next by thread: Re: modifying Kallal's Multiselect database example
- Index(es):
Relevant Pages
|