This is for a grades program for a college English class. Every activity, such as an essay, is in a group. Every group is associated with a course (an English class). When opening the activities form, I only want to display the activities within whichever group is already selected on the previous form which is filtered according to another open form, frmSelectCourse.
The button's click subroutine generates the following error: "Runtime error '3061': Too few parameters. Expected 1."
However, it works fine in the query designer. That's how I created the query in the first place. I know I didn't misspell any field or table names because I simply copied the SQL code from the query designer.
Code:
Private Sub cmdOpenActivitiesForm_Click()
Dim StrSQL As String
StrSQL = "SELECT tblActivities.ActivityID "
StrSQL = StrSQL & "FROM (tblCourses INNER JOIN tblGroups "
StrSQL = StrSQL & "ON tblCourses.CourseCode = tblGroups.CourseCode) "
StrSQL = StrSQL & "INNER JOIN tblActivities "
StrSQL = StrSQL & "ON tblGroups.GroupID = tblActivities.GroupID "
StrSQL = StrSQL & "WHERE (((tblGroups.CourseCode)=[Forms]! "
StrSQL = StrSQL & "[frmSelectCourse].[cboSelectCourse]));"
Dim db As DAO.Database, rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset(StrSQL, dbOpenDynaset)
Dim intActivityCount As Integer
intActivityCount = rs.recordcount
' to avoid an invalid "use of null" error. . .
If intActivityCount > 0 Then
DoCmd.OpenForm frmActivities
Else
DoCmd.OpenForm frmActivitiesDataEntry
' similar form, but not filtered and in "data entry" mode
End If
End Sub
I wonder what I'm doing wrong.
Maybe there is a simpler solution.
Thanks!