Option Compare Database Option Explicit

Private Sub Form_Load()

' Add preliminary items to the list box.

IstMovies.Addltem "Episode I"

IstMovies.Addltem "Matrix"

IstMovies.Addltem "Conspiracy Theory"

IstMovies.Addltem "Men in Black"

End Sub

Private Sub cmdRemoveItem_Click()

' Has the user selected an item first? If lstMovies.Listlndex = -1 Then

' The user has not selected an item. MsgBox "Select an item to remove."


' The user selected an item, so remove it. lstMovies.Removeltem lstMovies.Listlndex

End If

End Sub

If no items in a list or combo box have been selected, the Listlndex is set to -1. Otherwise the Listlndex contains the index of the currently selected item (starting with index 0 for the first item). This means you can pass the Listlndex property value to the Removeltem method. This is an efficient and dynamic means of using property values to pass parameters to methods.

0 0

Post a comment