Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Limit multi-select to seven

Status
Not open for further replies.

rafe

Technical User
Aug 18, 2000
194
US
Hi All,

I’m trying to use the multi-select property on a list box, but… I want to limit the number of selections to seven. I’ve been trying to use the following….

Private Sub IndexAccount_BeforeUpdate(Cancel As Integer)
[tab]Static indexAccountSelected(0 To 7) As Long
[tab]indexAccountSelected(IndexAccount.ItemsSelected.Count-1) = IndexAccount.ItemsSelected.???
[tab]If IndexAccount.ItemsSelected.Count = 8 Then
[tab] [tab]IndexAccount.Selected(indexAccountSelected(7)) = False
[tab] [tab]Cancel = True
[tab]End If
[tab]SelectCount = IndexAccount.ItemsSelected.Count
End Sub

Desired behavior is to make the eighth selection appear to not happen. I can make the eight selected item down the list unselect but that gets odd if items are selected in random order.

I’m stumped & I didn’t see it in Access help or in the Tek-Tips FAQs or history. Grrrrr! OK, I’m a newbie to VBA but I gotta learn sometime.
 
OK, I answered my own question... code could be...

Private Sub IndexAccount_BeforeUpdate(Cancel As Integer
[tab]Static indexAccountSelected(0 To 7) As Long
[tab]indexAccountSelected(IndexAccount.ItemsSelected.Count - 1) = IndexAccount.ListIndex + 1
[tab]If IndexAccount.ItemsSelected.Count = 8 Then
[tab][tab]IndexAccount.Selected(indexAccountSelected(7)) = False
[tab][tab]Cancel = True
[tab]End If
[tab]SelectCount = IndexAccount.ItemsSelected.Count
End Sub

thanks anyway
 
Hey, rafe. Do you talk to yourself out loud too! Its great that you post the answers. I have marked alot of stuff for email notification and never find out what the solution was.

Thanks for the posting. [sig]<p>John A. Gilman<br><a href=mailto:gms@uslink.net>gms@uslink.net</a><br>[/sig]
 
Why yes I do.... mmmm....

fyi: the code can be cut down considerably to...

Private Sub List0_BeforeUpdate(Cancel As Integer)
If List0.ItemsSelected.Count = 8 Then
List0.Selected(List0.ListIndex) = False
Cancel = True
End If
End Sub

(maybe further cuts could be made) i posted before the final version

thanks, it seems to be in the spirit of things to post the answers too

rafe
[sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top