[RESOLVED] How to make names of listbox items appear on a message box?
On the form are 1 listbox and one commandbutton, among others. The command button is for deleting items inside the listbox. If the user clicks the DELETE button, a message box would appear saying "Delete *****, *****, *****?"...I already have the complete code for this procedure, what I need is the code that will make the names of the items appear on the msgbox, example - the message on the message box would read something like this: Delete Apple, Orange, Banana, Lemon? -this is assuming that the user selected Apple, Orange, Banana, and Lemon in the listbox. I need the EXACT code. Thanks a lot!!!
Re: How to make names of listbox items appear on a message box?
i threw this together real quick, it should work. change your objects as needed
VB Code:
Private Sub Command1_Click()
Dim i As Long
Dim sCount As Long
Dim Msg As String
If List1.SelCount = 0 Then
Exit Sub
End If
Msg = "Delete"
For i = 0 To List1.ListCount - 1
If List1.Selected(i) Then
sCount = sCount + 1
Msg = Msg & IIf((sCount = List1.SelCount) And (sCount > 1), " and", vbNullString)
Msg = Msg & " " & List1.List(i) & ","
End If
Next i
Mid$(Msg, Len(Msg)) = "?"
MsgBox Msg, vbYesNo, "Delete Items"
End Sub
Re: How to make names of listbox items appear on a message box?
Why not just design your own form that displays what you want just like a msgbox. This way you can control everything about it.