我有一个列表框控件,可以填充选中的项目列表到MsgBox,但是当我运行它时,我一直收到错误代码。
错误:编译错误:找不到方法或数据成员
我做错了什么?
Private Sub ctrSend_Click()
Dim msg As String
Dim i As Integer
Dim lstMsg As ListBox
If lstShipping.ListIndex = -1 Then
msg = "Nothing"
Else
msg = ""
For i = 0 To lstShipping.ListCount - 1
If lstShipping.Selected(i) Then _
msg = msg & lstMsg.List(i) & vbCrLf
Next i
End If
MsgBox "You selected: " & vbCrLf & msg, vbOKOnly, "Selected BIN"
Unload Me
End Sub
答案 0 :(得分:0)
您正在循环使用lstShipping,但正在查看来自lstMsg的项目。这真的是你想要做的吗?如果没有,请将lstMsg更改为lstShipping,如下所示:
Private Sub ctrSend_Click()
Dim msg As String
Dim i As Integer
Dim oItem as Variant
' Dim lstMsg As ListBox
If lstShipping.ListIndex = -1 Then
msg = "Nothing"
Else
msg = ""
For Each oItem in lstShipping.ItemsSelected
msg = msg & lstShipping.ItemData(oItem) & vbCrLf ' <--- lstShipping!
Next
End If
MsgBox "You selected: " & vbCrLf & msg, vbOKOnly, "Selected BIN"
DoCmd.Close
End Sub