Uncheck Items in ListBox.

P

Prohock

I have a list box called "ListPrint". The Control is "PrintValue" (from the
table TbPrintValue) the Rowsource is "TbPrintForm" (Table that has all the
list box items) and the form's record source is "TbPintValue". I have the
following code to reset the form so that the check boxes in the list box can
be checked again. Unfortunately it does not work and the items checked
remained checked. Please help.

Private Sub Form_Close()
Dim varItem As Variant

For Each varItem In Me!ListPrint.ItemsSelected
Me!ListPrint.Selected(varItem) = False
Next varItem
End Sub
 
T

Tom Wickerath

Hi "Prohock",

The code you indicated should give you a compile error when/if you attempt
to compile your code (Debug | Compile {ProjectName} ), where {ProjectName} is
the name of your VBA Project. The reason is that .ItemsSelected requires
arguments that are not optional. Try this instead:

For Each varItem In Me!ListPrint.ListCount - 1


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
__________________________________________
 
J

JimBurke via AccessMonster.com

I could be wrong about thsi, but I don't think that's right either -
listcount is simply a property that tells you the number of items in the list,
so I wouldn't think you could navigate it through it with a 'for each'. If
you want to reset all items in the list, something like this would work:

dim i as long
For i = 0 To Me!ListPrint.ListCount - 1
Me!ListPrint.Selected(i) = False
next i
Hi "Prohock",

The code you indicated should give you a compile error when/if you attempt
to compile your code (Debug | Compile {ProjectName} ), where {ProjectName} is
the name of your VBA Project. The reason is that .ItemsSelected requires
arguments that are not optional. Try this instead:

For Each varItem In Me!ListPrint.ListCount - 1


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
__________________________________________
I have a list box called "ListPrint". The Control is "PrintValue" (from the
table TbPrintValue) the Rowsource is "TbPrintForm" (Table that has all the
[quoted text clipped - 10 lines]
Next varItem
End Sub
 
P

Pendragon

I use the following in a command button on a form to clear all selections.
Essentially the same as what you have except the With/End With. If this
doesn't work, as always, double check control names, etc.

With Me.lstGroup
For Each varSelected In .ItemsSelected
.Selected(varSelected) = False
Next
End With
 
P

Prohock

Thank you for your help!

I added the original code that I posted to a button (On CLick) and it
worked. I had it originally located (On Close). I don't know why it does not
work when you click the access close button for the form and it does work on
the close button I created?
 
J

JimBurke via AccessMonster.com

Looking at your original post again, I should have noticed that! The code was
OK, it was just in the wrong place. Putting it in the form close event
doesn't really do anything for you, since as soon as the code is executed the
form closes. The code I posted is less efficient, since it goes thru every
item, whereas your code, as it should, only looks at the items that were
selected and resets those.
Thank you for your help!

I added the original code that I posted to a button (On CLick) and it
worked. I had it originally located (On Close). I don't know why it does not
work when you click the access close button for the form and it does work on
the close button I created?
I use the following in a command button on a form to clear all selections.
Essentially the same as what you have except the With/End With. If this
[quoted text clipped - 20 lines]
 

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