You really should have posted this as a new question, but let me see if
I can work out a solution to your problem.
Earlier you were tasking about multiselect list boxes, but I now you
must be dealing with a "regular", non-multiselect list box, because
multiselect list boxes already behave the way you want. That is,
clicking on a selected row deselects it. But this is not the normal
behavior for a non-multiselect list box.
If the list box is bound, pressing the Esc key will undo the change you
just made to it, but that won't work if it's unbound, and it's not
exactly the behavior you want: "click selected item to deselect it".
You could try code like this in the list box's Click event:
'----- start of proposed code -----
Private Sub lstMyList_Click()
Static vOldValue As Variant
If Me.lstMyList = vOldValue Then
Me.lstMyList = Null
End If
vOldValue = Me.lstMyList
End Sub
'----- end of proposed code -----
Note that this won't work for a multiselect list box, because they don't
have a single value. But the problem doesn't arise for multiselect list
boxes anyway. Note also that, if the list box is bound to a required
field, you'll get an error message when you try to set it to Null. The
only way around that, that I can think of offhand, is to check whether
the control is bound; if it is, use the control's Undo method to undo
the selection rather than setting the list box to Null. That wouldn't
be quite the behavior you want, though, since the list box could be set
to a non-null value that it had before you clicked on it.
--
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)