first multiselect listbox item selected

supmktg

Registered User.
Local time
Today, 16:08
Joined
Mar 25, 2002
Messages
360
I have a multiselect listbox on a form, and a command button which brings up a record detail form. If the user selects only one item in the listbox it works great. If the user selects multple items in the listbox, it shows the LAST record selected. I would like to show the FIRST record selected. How can I specify the first selected item?

Here's the code behind my command button:
Code:
Private Sub cmdViewDetail_Click()
   
    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "frmDetail"
    stLinkCriteria = "[RecID] = " & Me.lstRecords.Column(0)

    DoCmd.OpenForm stDocName, , , stLinkCriteria
End Sub

Ultimately, on frmDetail I would like to include buttons that will navigate through the selected items in the listbox. For now, I'm just trying to get to the first selected item.

Thanks,
Sup
 
here's an example. Listbox multi setect property = extended

Dim x As Integer

For x = 0 To listbox.ListCount - 1
If istbox.Selected(x) Then
MsgBox istbox.Column(0, x)
End If
Next x
 
This is my new code behind cmdViewDetail which does open the first record:

Code:
Private Sub cmdViewDetail_Click()
   
    Dim stDocName As String
    Dim stLinkCriteria As String
    Dim x As Integer
    stDocName = "frmDetail"

    For x = 0 To lstProcedures.ListCount - 1
    If lstRecords.Selected(x) Then
    stLinkCriteria = "[RecID] = " & Me.lstRecords.Column(0, x)
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    Exit Sub
    End If
    Next x
        
End Sub

Thanks,
Sup
 

Users who are viewing this thread

Back
Top Bottom