A
Ann
I am using Access 2002. I have the following code on a button. This code
allows me to pick multiple Course Titles from a list box and generate reports
for only those I've chosen. Now I need to add a second piece of criteria to
the list. I now have txtCourseTitle and dtmStartDate. I need the date too
because the same course can be listed more than once. I didn't write the
code below so I'm not sure how to change it. I tried adding it to temp = in
the Else statement but it didn't work. Can anyone help me out? Thanks in
advance.
Private Sub Command8_Click()
Dim frm As Form, ctl As ListBox, var As Variant
Dim strCriteria As String, temp As String
Set frm = Forms!frmSummaryOfEvaluationsByCourseParameter
Set ctl = frm!lstCourses
'If no selection, display warning and exit
If ctl.ItemsSelected.Count = 0 Then
MsgBox "Please select a course."
Exit Sub
'builds SQL WHERE clause
'using each of the selected projects
Else
For Each var In ctl.ItemsSelected
temp = "[txtCourseTitle] = " & Chr(39) & _
ctl.ItemData(var) & Chr(39) & " Or "
strCriteria = strCriteria & temp
Next var
End If
'deletes the final Or from the WHERE clause
strCriteria = Left$(strCriteria, Len(strCriteria) - 4)
'outputs report
On Error GoTo ErrorOpen
DoCmd.OpenReport "rptSummaryOfEvalutionsByCourse", acViewPreview, ,
strCriteria
ExitOpen:
Exit Sub
ErrorOpen:
If Err = 2501 Then
Resume ExitOpen
Else
MsgBox Err.Description
Resume ExitOpen
End If
Set ctl = Nothing
Set frm = Nothing
End Sub
allows me to pick multiple Course Titles from a list box and generate reports
for only those I've chosen. Now I need to add a second piece of criteria to
the list. I now have txtCourseTitle and dtmStartDate. I need the date too
because the same course can be listed more than once. I didn't write the
code below so I'm not sure how to change it. I tried adding it to temp = in
the Else statement but it didn't work. Can anyone help me out? Thanks in
advance.
Private Sub Command8_Click()
Dim frm As Form, ctl As ListBox, var As Variant
Dim strCriteria As String, temp As String
Set frm = Forms!frmSummaryOfEvaluationsByCourseParameter
Set ctl = frm!lstCourses
'If no selection, display warning and exit
If ctl.ItemsSelected.Count = 0 Then
MsgBox "Please select a course."
Exit Sub
'builds SQL WHERE clause
'using each of the selected projects
Else
For Each var In ctl.ItemsSelected
temp = "[txtCourseTitle] = " & Chr(39) & _
ctl.ItemData(var) & Chr(39) & " Or "
strCriteria = strCriteria & temp
Next var
End If
'deletes the final Or from the WHERE clause
strCriteria = Left$(strCriteria, Len(strCriteria) - 4)
'outputs report
On Error GoTo ErrorOpen
DoCmd.OpenReport "rptSummaryOfEvalutionsByCourse", acViewPreview, ,
strCriteria
ExitOpen:
Exit Sub
ErrorOpen:
If Err = 2501 Then
Resume ExitOpen
Else
MsgBox Err.Description
Resume ExitOpen
End If
Set ctl = Nothing
Set frm = Nothing
End Sub