×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Limit multi-select to seven

Limit multi-select to seven

Limit multi-select to seven

(OP)
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)
    Static indexAccountSelected(0 To 7) As Long
    indexAccountSelected(IndexAccount.ItemsSelected.Count-1) = IndexAccount.ItemsSelected.???
    If IndexAccount.ItemsSelected.Count = 8 Then
         IndexAccount.Selected(indexAccountSelected(7)) = False
         Cancel = True
    End If
    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.

RE: Limit multi-select to seven

(OP)
OK, I answered my own question... code could be...

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

thanks anyway

RE: Limit multi-select to seven

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.

John A. Gilman
gms@uslink.net

RE: Limit multi-select to seven

(OP)
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close