Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Other Forums
 MS Access
 unselecting an item in a listbox

Author  Topic 

KnooKie
Aged Yak Warrior

623 Posts

Posted - 2002-05-23 : 06:07:10
Is there an easy way of unselecting an item in a list box using VBA ??

Is there a way of unselecting without having to loop through the whole list and use the select property ?? I assume that will do it.

thanks
Paul

Paul

KnooKie
Aged Yak Warrior

623 Posts

Posted - 2002-05-23 : 06:55:21
answer......

Dim intCurrentRow As Integer

For intCurrentRow = 0 To lst.ListCount - 1
If lst.Selected(intCurrentRow) = True Then
lst.Selected(intCurrentRow) = False
Exit For
End If
Next intCurrentRow

Paul
Go to Top of Page

KnooKie
Aged Yak Warrior

623 Posts

Posted - 2002-05-23 : 08:53:11
Although the above code works i was unable to write it as a Global Module passing in the form and listbox name. If anyone has any ideas that'd be great.

Paul
Go to Top of Page

RatTail
Crackhead

98 Posts

Posted - 2002-05-24 : 12:25:43
Hi, KnooKie!
Try as following:
' global function

Function WhatYouNeed(ByVal NameOfForm As String)
Dim i
DoCmd.OpenForm NameOfForm, acNormal
For Each i In Screen.ActiveForm.NameOfListBox.ItemsSelected
................................................
Next
End Function


Go to Top of Page

RatTail
Crackhead

98 Posts

Posted - 2002-05-24 : 15:28:46
forgot the second parameter: listbox's name

Function WYN(ByVal fn, lbn)
Dim i

DoCmd.OpenForm fn, acNormal
Screen.ActiveForm.Controls(lbn).SetFocus
For Each i In Screen.ActiveControl.ItemsSelected
................................................
Next

End Function

Go to Top of Page

RatTail
Crackhead

98 Posts

Posted - 2002-05-25 : 07:06:06
forgot: to avoid looping thru all rows of the listbox use:

For Each i In Screen.ActiveControl.ItemsSelected
Screen.ActiveControl.Selected(i) = False
Next


Believe that's all you need.


Go to Top of Page

KnooKie
Aged Yak Warrior

623 Posts

Posted - 2002-05-27 : 07:39:21
Many Thanks

I will give it a go

Paul
Go to Top of Page
   

- Advertisement -