在Excel中,我正在更新一个标记列表框中所选项目的标签。每当我取消选择一个标签就会倒数一个。我用这个代码:
作为整数昏暗朦胧intIndex intCount作为整数
With ListBox6
For intIndex = 0 To .ListCount - 1
If .Selected(intIndex) Then intCount = intCount + 1
Next
End With
Label1.Caption = "Deelnemers: " & intCount & " op " & ListBox6.ListCount
我试图在访问中做同样的事情,但它不起作用。
为了回答您的问题,我们可能需要额外的信息。 - 你收到错误信息吗? - label1和listbox6在哪里? - 什么触发代码?您(尝试)使用哪个事件?
Dim intIndex As Integer
Dim intCount As Integer
intcount = 0
With **Form1.**ListBox6
For intIndex = 0 To .ListCount - 1
If .Selected(intIndex) Then
intCount = intCount + 1
End if
Next
**Me.**Label1.Caption = "Deelnemers: " & intCount & " op " & .ListCount
End With
你也可以为每个循环尝试一个;
Dim Li as listitem
dim seleciontcount as integer
selectioncount = 0
For each li in listbox6.items
if li.selected then
selectioncount = selectioncount + 1
end if
next