Form firing wrong event

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a weird problem happening in an Access form. My form has several list
boxes on it. If the user selects something from List Box A it limits there
choices for List Box B. This code works fine. However if I put a line of
code to in List Box A to deselect any choices from List Box B screws things
up. It makes it fire the Click event for List Box A no matter what control
on the form is clicked. My code works perfect if I put it in a command
button. As soon as I put it in the click event for a list box it stops
working. Here is a simplified version of the code I'm using. If I take out
the last line of code it works fine. However I need that line to deselect
anything in the second list box. Any help would be greatly appreciated.

Private Sub lstCategory_Click()
lstFlavor.RowSource = "SELECTION CRITERIA"
lstFlavor.Requery
lstFlavor.Selected(lstFlavor.ListIndex) = False
End Sub
 
Your code works for me. The selection critieria query is just something
like ....

select flavor from flavors where category=forms!formname!lstCategory ?

Runnning it here, given that the query is updating and displaying a
completely separate list of flavours, any selections from the second listbox
are disappearing anyway. But even if I click on other controls then
everything is working fine.

I'd suggest that maybe you have something else going on in the background.
Try rebuilding the form from scratch starting with the list boxes and see
where it goes wrong.
 
That last line
lstFlavor.Selected(lstFlavor.ListIndex) = False
looks odd to me, for this reason:
lstFlavor.ListIndex
would typically be used to define the (single) selected item in a
single-select listbox.
lstFlavor.Selected
would typically be used in a multi-select listbox.
So I would not be surprised that you get unexpected results when you try to
use them together.
Although I certainly would not have predicted the result you report.

One "quick and dirty" way to remove all selections in a single-select
listbox is to set its value equal to something that's not in the list - an
empty string, for example.
Remember, though, that if the listbox is bound to a field, this value
will still be stored in the field, even if you don't see it in the control.

HTH
 
Back
Top