A
Ann
I am using MS Access 2002. I have a response table, tblSurveyMonkeyAppend.
I have a listbox that gives me the names of courses, [txtCourseTitle] from
this table. Sometimes a course can have one response or many responses. I
use a listbox of course titles to choose one or more courses. Then I run a
report for just those courses. Here is the code:
Private Sub cmdBarChart_Click()
Dim frm As Form, ctl As ListBox, var As Variant
Dim strCriteria As String, temp As String
Set frm = Forms!frmSurveyMonkeyParameter
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 "rptBarCharts", 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
What I want to know is can this code be altered to run a delete query with
the txtCourseTitle chosen instead of a report. I've tried to change the
DoCmd.OpenReport "rptBarCharts", acViewPreview, , strCriteria line to open
the delete query but I get an error that it can't be found. I am not a
programmer so I really don't know if this would even work if it could find
the query. These responses need to be deleted at the end of each quarter and
brought down again and they are cumulative. Thanks in advance for any help
you can offer.
I have a listbox that gives me the names of courses, [txtCourseTitle] from
this table. Sometimes a course can have one response or many responses. I
use a listbox of course titles to choose one or more courses. Then I run a
report for just those courses. Here is the code:
Private Sub cmdBarChart_Click()
Dim frm As Form, ctl As ListBox, var As Variant
Dim strCriteria As String, temp As String
Set frm = Forms!frmSurveyMonkeyParameter
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 "rptBarCharts", 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
What I want to know is can this code be altered to run a delete query with
the txtCourseTitle chosen instead of a report. I've tried to change the
DoCmd.OpenReport "rptBarCharts", acViewPreview, , strCriteria line to open
the delete query but I get an error that it can't be found. I am not a
programmer so I really don't know if this would even work if it could find
the query. These responses need to be deleted at the end of each quarter and
brought down again and they are cumulative. Thanks in advance for any help
you can offer.