ppoindexter
Registered User.
- Local time
- Yesterday, 22:48
- Joined
- Dec 28, 2000
- Messages
- 134
i am using a form with 2 list boxes to pass selected values to a query/report
this code works if i select only 1 item from each list box, when i select different combinations of values (for example 2 items from LBox_Grades and 1 from LBox_Standards or varous other combinations) the report opens with the wrong records..also it doesnt handle null values (report will not open if either list box has no items selectioned)
any ideas?
Private Sub Command8_Click()
Dim varItem As Variant
Dim strWhere As String
Dim strWhereGrades As String
Dim strWhereStandards As String
Dim stDocName As String
If IsNull(Me.Combo_Report) = True Then
MsgBox ("Please select a Report")
Else
For Each varItem In Me![LBox_Grades].ItemsSelected
strWhereGrades = strWhereGrades & "fldlevel2id =" _
& Me![LBox_Grades].Column(0, varItem) & " Or "
Next varItem
strWhereGrades = Left(strWhereGrades, Len(strWhereGrades) - 4)
For Each varItem In Me![LBox_Standards].ItemsSelected
strWhereStandards = strWhereStandards & "fldlevel1id =" _
& Me![LBox_Standards].Column(0, varItem) & " Or "
Next varItem
strWhereStandards = Left(strWhereStandards, Len(strWhereStandards) - 4)
strWhere = strWhereGrades & " And " & strWhereStandards
stDocName = Me![Combo_Report].Column(2)
DoCmd.OpenReport stDocName, acPreview, , strWhere
end sub
this code works if i select only 1 item from each list box, when i select different combinations of values (for example 2 items from LBox_Grades and 1 from LBox_Standards or varous other combinations) the report opens with the wrong records..also it doesnt handle null values (report will not open if either list box has no items selectioned)
any ideas?
Private Sub Command8_Click()
Dim varItem As Variant
Dim strWhere As String
Dim strWhereGrades As String
Dim strWhereStandards As String
Dim stDocName As String
If IsNull(Me.Combo_Report) = True Then
MsgBox ("Please select a Report")
Else
For Each varItem In Me![LBox_Grades].ItemsSelected
strWhereGrades = strWhereGrades & "fldlevel2id =" _
& Me![LBox_Grades].Column(0, varItem) & " Or "
Next varItem
strWhereGrades = Left(strWhereGrades, Len(strWhereGrades) - 4)
For Each varItem In Me![LBox_Standards].ItemsSelected
strWhereStandards = strWhereStandards & "fldlevel1id =" _
& Me![LBox_Standards].Column(0, varItem) & " Or "
Next varItem
strWhereStandards = Left(strWhereStandards, Len(strWhereStandards) - 4)
strWhere = strWhereGrades & " And " & strWhereStandards
stDocName = Me![Combo_Report].Column(2)
DoCmd.OpenReport stDocName, acPreview, , strWhere
end sub