有没有办法限制用户在 Access 2003 中启用了多选功能的列表框中可以选择的选项数量?现在,我有一个在“单击”事件上触发的过程,该过程检查所选选项的数量,如果超过我的阈值,它将显示一个警告标签。
尝试一下。如果最后选择的项目超过预定义的限制,它基本上会取消选择:
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
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
10029 次 |
最近记录: |