Reputation: 225
I have a listbox control that is suppose to populate a list of the items selected into a MsgBox, but I keep getting an error code when I run it.
ERROR: Compile error: Method or data member not found
What am I doing wrong?
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
Upvotes: 1
Views: 4626
Reputation: 487
You are looping on lstShipping, yet looking at items from lstMsg. Is that really what you want to do? If not, change lstMsg to lstShipping as below:
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
Upvotes: 0