Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Issue in listbox.itemsselected after unselecting an item in listbox

Status
Not open for further replies.

MickelR

Technical User
Mar 10, 2010
21
NL
I am running MS Access 2003. I have a multiselect listbox, using the simple property in multi select. In the same form, I have a button that triggers opening a report, using a where condition. The code of that button is:
Code:
Private Sub butCreateReports_Click()

    Dim varItem As Variant
    Dim strReport As String
    Dim strFilter As String
    Dim datExerciseDate As Date
    Dim dblPosition As Double
    
    Me.cboTable.SetFocus
    
    For Each varItem In Me.lstMainScreen.ItemsSelected
    Stop
        Select Case Me.lstMainScreen.Column(2)
        Case "Report1"
            strReport = "rptReport1"
        Case Else
            MsgBox ("A report for this recordset does not exist")
            GoTo NextItem
        End Select
        
        datExerciseDate = Format(Me.lstMainScreen.Column(1), "mm/dd/yyyy")
        dblPosition = Me.lstMainScreen.Column(7)
        strFilter = "[CustomerID] = '" & Me.lstMainScreen.Column(0) & "' AND [IssuerID] = '" & Me.lstMainScreen.Column(2) & "' AND [ISIN] = '" & Me.lstMainScreen.Column(3) & "' AND [Position] = " & dblPosition & _
            " AND [ExerciseDate] = #" & datExerciseDate & "#"
        
        DoCmd.OpenReport strReport, acViewPreview, , strFilter

NextItem:
    Next varItem
    
        
End Sub
The last action I do before clicking the "butCreateReports" button would be unselecting an item in the listbox. The issue that arises after clicking the button, is that the first varItem in Me.lstMainScreen.ItemsSelected is the last unselected (!) item (which was my last action). Obviously I do not want this item running through this code, because I unselected it.

Does anyone have a solution to this?
 
Great! I found the solution myself. This might be useful for those coming across the same problem.

the Listbox.Column property also works with rows!!! So, to solve this mystery in my example, I have to use me.lstMainScreen.Column(#ColumnNumber, varItem) where varItem is the rownumber of each selected record.

Happy coding! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top