gpt4 book ai didi

vba - 限制多选列表框中的选择数

转载 作者:行者123 更新时间:2023-12-05 08:44:47 27 4
gpt4 key购买 nike

在 Access 2003 中启用了 MultiSelect 的情况下,是否有一种方法可以限制用户可以在 ListBox 上选择的选项数量?现在我有一个程序会在 On Click 事件上触发,该事件会检查所选选项的数量,如果超过我的阈值,它将显示警告标签。

最佳答案

试一试。如果超过预定义的限制,它基本上会取消选择最后选择的项目:

Private Sub ListBox1_Change()

Dim counter As Integer
Dim selectedCount As Integer

selectedCount = 0

For counter = 1 To ListBox1.ListCount Step 1
If ListBox1.Selected(counter - 1) = True Then 'selected method has 0 base
selectedCount = selectedCount + 1
End If
Next counter

If selectedCount >= 4 Then 'modify # here
ListBox1.Selected(ListBox1.ListIndex) = False 'listindex returns the active row you just selected
MsgBox "Limited to 4 Choices", vbInformation + vbOKOnly, "Retry:"
End If
End Sub

关于vba - 限制多选列表框中的选择数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1406973/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com