To Albert D. Kallal- Multiselect list box question

  • Thread starter serviceman via AccessMonster.com
  • Start date
S

serviceman via AccessMonster.com

Calling Dr. Kallal....
I have been making use of your nice little multiselect form to add students
to my attendance forms. I need to add a button to the form that will select
ALL students. This simple code:
Private Sub Command14_Click()

If IsChecked(Me.STUDENT_ID) = False Then
colCheckBox.Add CLng(Me.STUDENT_ID), CStr(Me.STUDENT_ID)
End If
Me.requery
End Sub

selects and de-selects whatever record has the focus, but I cannot get it to
loop through all records in the form to check all students. How can I get it
to loop? i have been farting around with this for several hours, and getting
nowheres fast....
Thanks again for all of your great contrbutions to this site; your insight is
most helpful!
andy
 
A

Albert D.Kallal

Hum, if you look at the sample, when NO boxes are checked, then the report
shows all records....

However, in your case, I have to agree, a "select" all button would be what
the doctor ordered...

I would try the following button code...see if it works....

dim rst as dao.recordset
set rst = me.RecordSetClone

rst.MoveFirst
do while rst.EOF = false
colCheckBox.Add CLng(rst!STUDENT_ID), CStr(rst!STUDENT_ID)
rst.movenext
loop
set rst = nothing

I think the above should do the trick...give it a try....
 
S

serviceman via AccessMonster.com

Albert,
Yes, I see that no selections return ALL records; problem was, the users
would see a screen full of empty check boxes and go click-crazy thinking
NOTHING was selected...

Your code, as usual, works. I notice, however, that if the user clicks the
button a second time (after all records have been 'checked'), then runtime
error 457 (key already assosiated with this element) comes up. I thought i
could avoid it by adding :

rst.MoveFirst
do while rst.EOF = false
colCheckBox.Add CLng(rst!STUDENT_ID), CStr(rst!STUDENT_ID)
rst.movenext
loop

But it then only selects the first record, and the same error will come up.
Is there a way to set this code so that if the record is checked, it ignores
it?
Ever-so-grateful-Andy
 
S

serviceman via AccessMonster.com

Albert,
Yes, I see that no selections return ALL records; problem was, the users
would see a screen full of empty check boxes and go click-crazy thinking
NOTHING was selected...

Your code, as usual, works. I notice, however, that if the user clicks the
button a second time (after all records have been 'checked'), then runtime
error 457 (key already assosiated with this element) comes up. I thought i
could avoid it by adding :

rst.MoveFirst
do while rst.EOF = false
colCheckBox.Add CLng(rst!STUDENT_ID), CStr(rst!STUDENT_ID)
rst.movenext
loop

But it then only selects the first record, and the same error will come up.
Is there a way to set this code so that if the record is checked, it ignores
it?
Ever-so-grateful-Andy
 
S

serviceman via AccessMonster.com

Albert,
I just noticed that the 'select all' code is only selecting those records
that are visible in the form; If there are more records than the form can
display without scrolling, they don't get selected...
andy
Albert,
Yes, I see that no selections return ALL records; problem was, the users
would see a screen full of empty check boxes and go click-crazy thinking
NOTHING was selected...

Your code, as usual, works. I notice, however, that if the user clicks the
button a second time (after all records have been 'checked'), then runtime
error 457 (key already assosiated with this element) comes up. I thought i
could avoid it by adding :

rst.MoveFirst
do while rst.EOF = false
colCheckBox.Add CLng(rst!STUDENT_ID), CStr(rst!STUDENT_ID)
rst.movenext
loop

But it then only selects the first record, and the same error will come up.
Is there a way to set this code so that if the record is checked, it ignores
it?
Ever-so-grateful-Andy
Hum, if you look at the sample, when NO boxes are checked, then the report
shows all records....
[quoted text clipped - 15 lines]
I think the above should do the trick...give it a try....
 
S

serviceman via AccessMonster.com

wow...
how odd... There is a couple second delay when scrolling, and then the boxes
check. I guess that your code is ok (of course), but the process time is a
bit behind..
Andy
Albert,
I just noticed that the 'select all' code is only selecting those records
that are visible in the form; If there are more records than the form can
display without scrolling, they don't get selected...
andy
Albert,
Yes, I see that no selections return ALL records; problem was, the users
[quoted text clipped - 24 lines]
 
A

Albert D.Kallal

wow...
how odd... There is a couple second delay when scrolling, and then the
boxes
check. I guess that your code is ok (of course), but the process time is a
bit behind..

ok....

For the "error" problem, we can just "empty" the colleciton, so we
don't errory out trying to add a already check box....
*before* we start...

So, just do

set colCheckBox = nothing ' <--- at this to clear all

rst.MoveFirst
do while rst.EOF = false
colCheckBox.Add CLng(rst!STUDENT_ID), CStr(rst!STUDENT_ID)
rst.movenext
loop
set rst = nothing
 
S

serviceman via AccessMonster.com

Albert,
works like a charm. Thank you so much for your time and efforts....
Andy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top