Results 1 to 6 of 6
  1. #1
    rghollenbeck is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Sep 2011
    Posts
    12

    3061 Error. Too few parameters. Expected 1.

    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!

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    You have to concatenate the form reference. Presuming CourseCode is numeric:

    StrSQL = StrSQL & "WHERE tblGroups.CourseCode=" & [Forms]![frmSelectCourse].[cboSelectCourse]

    If it's text:

    StrSQL = StrSQL & "WHERE tblGroups.CourseCode='" & [Forms]![frmSelectCourse].[cboSelectCourse] & "'"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    rghollenbeck is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Sep 2011
    Posts
    12
    Works like a charm! Thank you.

    Also I needed to put quotation marks around the table names like this:

    Code:
    If intActivityCount > 0 Then
        DoCmd.OpenForm "frmActivities"
    Else
        DoCmd.OpenForm "frmActivitiesDataEntry"
    End If
    Thank you very much!


  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Ah yes, you would; I never looked down that far. As an aside, you can't count on the recordcount:

    http://www.baldyweb.com/RecordCounts.htm

    though for what you're doing it may work. I'd just test for EOF, since all you really care about is whether there are any records. Also, I'd have a single form and either open it filtered:

    BaldyWeb wherecondition

    or use the data mode argument of OpenForm to open it in data entry mode. I'm lazy, and don't like to maintain two forms if I can get away with one.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    rghollenbeck is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Sep 2011
    Posts
    12
    Quote Originally Posted by pbaldy View Post
    Ah yes, you would; I never looked down that far. As an aside, you can't count on the recordcount:

    http://www.baldyweb.com/RecordCounts.htm

    though for what you're doing it may work. I'd just test for EOF, since all you really care about is whether there are any records. Also, I'd have a single form and either open it filtered:

    BaldyWeb wherecondition

    or use the data mode argument of OpenForm to open it in data entry mode. I'm lazy, and don't like to maintain two forms if I can get away with one.
    I will need to study this. The first form is filtered to only allow activity records related to the current group. If there are no activities in the current group yet, the other form isn't filtered so it does not generate an "invalid use of null error." I tried filtering using the ac_arguments in the DoCmd.OpenForm but it wasn't working right so I put it back the way I had it and I will keep it that way until I understand how to use all those arguments. If I can figure out how to do it correctly, I can delete the second form.

    Also I will check out the links you have here.

    Thanks much!

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    No problem. To clarify, I'd still have the recordset and the If/Then, I'd just open the same form one of two different ways depending on whether there were records.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 05-21-2011, 01:33 AM
  2. Error 3061 Too Few Parameters Expecting 1
    By ironman in forum Programming
    Replies: 4
    Last Post: 05-09-2011, 03:20 PM
  3. Too few parameters expected 4
    By forestgump in forum Programming
    Replies: 1
    Last Post: 04-15-2011, 09:10 AM
  4. Run-time '3051' - Too few parameters. Expected 1
    By jgelpi16 in forum Programming
    Replies: 3
    Last Post: 04-11-2011, 07:17 AM
  5. Too few parameters. Expected 2.
    By PPCMIS2009 in forum Access
    Replies: 0
    Last Post: 01-28-2009, 01:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums