我有一个列表框控件,该控件应该将所选项目的列表填充到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
您正在循环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
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句