Ms access 检查访问表单列表框无选择
我正在尝试查看列表框是否为空。我已经看到了使用的建议Ms access 检查访问表单列表框无选择,ms-access,Ms Access,我正在尝试查看列表框是否为空。我已经看到了使用的建议 If IsNull(txtLevel) Then MsgBox "No Item is Selected" 但即使选择了项目,也会返回错误MsgBox 我在使用其他代码时遇到的另一个问题是,如果txtLevel.ListIndex=“-1”或如果txtLevel.ListCount=0,则它在第一次运行时效果良好,但如果选择然后取消选择,则不会触发错误消息 编辑:对我来说有效的答案是:如果txtLevel.ItemsSelected
If IsNull(txtLevel) Then
MsgBox "No Item is Selected"
但即使选择了项目,也会返回错误MsgBox
我在使用其他代码时遇到的另一个问题是,如果txtLevel.ListIndex=“-1”
或如果txtLevel.ListCount=0
,则它在第一次运行时效果良好,但如果选择然后取消选择,则不会触发错误消息
编辑:对我来说有效的答案是:
如果txtLevel.ItemsSelected.Count=0
您也可以使用.ItemsSelected
属性,该属性返回一个变量数组,其中包含所选条目的行号,或.Selected
属性,该属性在选择参数中指定的行时返回True
。您也可以使用.ItemsSelected
属性,该属性返回包含所选条目的行号的变量数组,或.Selected
属性,该属性在选择参数中指定的行时返回True
。尝试此代码-查看是否可以在该属性中看到您的解决方案。我留下评论来解释发生了什么
- ComboData是一个combobox控件
- CheckNoComboData是一个复选框控件
- CheckSelection是一个复选框控件
- CheckNoSelection是一个复选框控件
试试这段代码-看看你是否能在这段代码中看到你的解决方案。我留下评论来解释发生了什么
- ComboData是一个combobox控件
- CheckNoComboData是一个复选框控件
- CheckSelection是一个复选框控件
- CheckNoSelection是一个复选框控件
有效的答案是“If txtLevel.ItemsSelected.Count=0”有效的答案是“If txtLevel.ItemsSelected.Count=0”这会像txtLevel.ItemsSelected=0吗?结果是对我有效的.ItemsSelected.Count。那么!你愿意投票选出任何有帮助的答案,并接受最有帮助的答案吗?这确保了最佳答案首先出现,并且已回答的问题不会出现在未回答的列表中。这是否类似于txtLevel.ItemsSelected=0?结果是.ItemsSelected.Count对我有效。那么!你愿意投票选出任何有帮助的答案,并接受最有帮助的答案吗?这样可以确保最佳答案首先出现,已回答的问题不会出现在未回答列表中。
Dim intIter As Integer
Dim boolItems As Boolean
' Check if there is no Row Source data
If Nz(Me.ComboData.RowSource, "") = "" Then
Me.CheckNoComboData = True
Else
Me.CheckNoComboData = False
End If
' Check if there is a row source, but no
' items resulting from that rowsource
If Me.ComboData.ListCount = 0 Then
Me.CheckNoComboData = True
Else
Me.CheckNoComboData = False
End If
' Check if any items in the listbox are selected or not
Items = False
' Loop through each item in the combobox
For intIter = 0 To (Me.ComboData.ListCount - 1)
' If its selected, then we know items are selected
If Me.ComboData.Selected(intIter) Then
Items = True
Exit For
End If
Next
' Return Results
Me.CheckSelection = Items
Me.CheckNoSelection = Not Items