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:
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?
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
Does anyone have a solution to this?