Highlighted Row in Listbox

G

Guest

I have a form with 2 listboxes on it. Is there a way to make the highlighted
row in one listbox unhighlight when a row in the other listbox is selected?

Thanks in advance!

Dwight
 
K

Ken Snell \(MVP\)

You could run code in the AfterUpdate event of the one listbox to unselect
the other listbox's selection. Are both listboxes set to "no multiselect"?
Or is either of them set to "multiselect" option?
 
G

Guest

Here is what I have been trying. It works but not very smoothly.
Example:
A row has been selected in List26.
I click a row in List101 and the List26_click event runs instead of the
List101_click
I click the same row a second time and then the List101_Click event runs.

Are you able to see what is wrong in my code?


Private Sub List101_Click()
Dim i As Integer
For i = 0 To Me.List26.ListCount - 1
Me.List26.Selected(i) = False
Next i
End Sub

Private Sub List26_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[PKEY] = '" & Me![List26] & "'"
Me.Bookmark = rs.Bookmark

End Sub

Private Sub List101_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object
Dim i As Integer
Set rs = Me.Recordset.Clone
rs.FindFirst "[PKEY] = '" & Me![List101] & "'"
Me.Bookmark = rs.Bookmark
End Sub

Private Sub List26_Click()
Dim i As Integer
For i = 0 To Me.List101.ListCount - 1
Me.List101.Selected(i) = False
Next i

End Sub
 
K

Ken Snell \(MVP\)

Then it's pretty simple -- just set the other listbox's value to Null:

Private Sub Listbox1Name_AfterUpdate()
Me.Listbox2Name.Value = Null
End Sub

Do the same for the other listbox's AfterUpdate event:

Private Sub Listbox2Name_AfterUpdate()
Me.Listbox1Name.Value = Null
End Sub
 
G

Guest

Dwight

Try this pair of code samples to clear the other list box in each case:

Private Sub List26_Click()
Me.List101.Value = Null
End Sub

Private Sub List101_Click()
Me.List26.Value = Null
End Sub

Add your own code for the events required after each list box is updated
 
G

Guest

Thanks Ken and Ridders.
Don't I feel stupid... thinking a problem is harder then it really is.

Dwight
 

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