Full Version: set as unselected in listbox
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
jon_a
I have the following code in my on double click section of a list box, this works fine but i need to ensure after the double click that the item remains unselected.

CODE

            Me.txtLbox1 = lbox1.Column(0)
            DoCmd.OpenForm "frmLessonTaskDisplay", , , , acFormReadOnly, acDialog
Alan_G
Try........

CODE
Dim intX As Integer
Me.txtLbox1 = Me.lbox1.Column(0)            
For intX = 0 To Me.lbox1.ListCount - 1
   Me.lbox1.Selected(intX) = False
Next intX
DoCmd.OpenForm "frmLessonTaskDisplay", , , , acFormReadOnly, acDialog
jon_a
Will that not deselect everything? I only want it to deselect the one that has been double clicked on
Alan_G
Are you using a multiselect or single select listbox ?

If it's not multi select, you can use....

CODE
Dim intX As Integer
Me.txtLbox1 = Me.lbox1.Column(0)            
intX = Me.txtLbox1.ListIndex
Me.lbox1.Selected(intX) = False
DoCmd.OpenForm "frmLessonTaskDisplay", , , , acFormReadOnly, acDialog
jon_a
thanks alan but i am using multi select. I bet that makes things hard.lol
Alan_G
Sorry, you need to give me a bit more info then........ wink.gif

With a multi select listbox, if it's set to Extended, then the very act of double clicking will deselect all selections except the one you've double clicked. If it's set to Simple then double clicking an item that's already selected will deselect it, and double clicking an unselected item will select it............

What is it exactly you want to do ?
jon_a
ok i have set the list box to multi select simple. what is supposed to happen is on double click a second form opens displaying some information, but on closing the newly opened form i want the selection i double clicked to be unselected. It is not an integral part of my DB but is a nice to have the knowledge.
Alan_G
Hi

The code I posted before should be what you want then, with a couple of lines switched round...........

CODE
Dim intX As Integer
Me.txtLbox1 = Me.lbox1.Column(0)            
intX = Me.txtLbox1.ListIndex
DoCmd.OpenForm "frmLessonTaskDisplay", , , , acFormReadOnly, acDialog
Me.lbox1.Selected(intX) = False


**untested air code
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.