Listbox showing wrong item (VBA)
<p>I got a listbox with a number of rows, and a command button to show some of the columns from that row, in a seperate window (pop-up). The problem is that the row that it gets the information from (i.e. the row that is considered selected) is not the row that is currently marked, but rather the one that was marked before that. </p>

<p>So if I select row 5 and click the command button, it will just show a blank pop-up (no row selected). If I then select row 10 and click the command button, it will show the information for row 5, and so on. Is this a known issue or am I just doing completely wrong?</p>

<pre><code>Private Sub cmdDetails_Click()
    'If the ListIndex is -1, no selection is made
    If lstItems.ListIndex = -1 Then
        MsgBox "No row selected", vbInformation, "No row selected"

    'If a selection is made, open the details form and fill in the details
    Else
        frmDetails.Show ' &lt;-- Move this to the end of the sub

        With lstItems
            For i = 0 To .ListCount - 1
                If .Selected(i) Then
                    frmDetails.txtBox1.Text = .List(i, 0)
                    frmDetails.txtBox2.Text = .List(i, 2)
                End If
            Next i
        End With

    End If

End Sub
</code></pre>