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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Limit muti-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) = ????
[tab]If IndexAccount.ItemsSelected.Count = 7 Then
[tab][tab]IndexAccount.Selected(IndexAccount.ItemsSelected(7)) = False
[tab][tab]Cancel = True
[tab]End If
End Sub

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.
 
oops, that should read... & this is the wrong forum vb not vba....sorry folks

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

i will edit my posts....i will edit my posts....i will edit my posts....


 
Answered my own question anyway... 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

sorry for the extraneous post
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top