Re: modifying Kallal's Multiselect database example

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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





.



Relevant Pages

  • Re: modifying Kallals Multiselect database example
    ... You say the control source of the checkbox is: ... Private Sub Command13_Click ... Private Function SelectAll() ... The problem is that if you apply a filter using the user interface (the ...
    (microsoft.public.access.formscoding)
  • Re: Creating a temporary table/query for subform
    ... What this table will do is summarize the data they've filtered and then ... "Percent") change depending on what the users want to filter. ... I also need to label each checkbox field to something usable for the ... and I believe that requires a table or a query. ...
    (microsoft.public.access.queries)
  • Re: Dealing with Tables in VBA
    ... n-1 paragraphs in any cell in the second column of any table after the ... "No Filter Required" ... Anytime the checkbox next to "No FIlter Required" is checked, ... Find a occurance of a text string "Data Filter Requirements" ...
    (microsoft.public.word.vba.general)
  • Re: IIf problem with <>
    ... I assume that your checkbox is in the header, and basically, what you want ... is to either turn off the filter or turn it on. ... selecting a tick box that indicates show completed jobs ... You are trying to construct a criteria cell for the query ...
    (microsoft.public.access.queries)
  • Re: Help me about Filter
    ... to filter a report or form based on values in controls on your form? ... group (data type = text) ... but i can selected any in checkbox and unselected to show what field i ... rssppd.ActiveConnection = con ...
    (microsoft.public.access.formscoding)