Results 1 to 4 of 4
  1. #1
    drhansenjr is offline Novice
    Windows 10 Office 365
    Join Date
    Mar 2021
    Posts
    14

    "Runtime error '3061': Too few parameters. Expected 1." on OpenRecordset Statement

    This is driving me nuts...



    I am trying to design a query within a form's Form_Current event code that returns the record ID and integer value of a field named "intFirstSpouseID" when a new record is selected in a combobox. I have tried a number of variations but each time get the error "Runtime error '3061': Too few parameters. Expected 1." on the OpenRecordset line The table name is "Members2" and the form name is "frmMembers2":




    Code:
    Private Sub Form_Current()
    
    
    Dim rstSpouse1Query As Recordset
    Dim currDB As Database
    Dim strSQLFirst As String
     
    Set currDB = CurrentDb
    strSQLFirst = "Select Members2.ID, Members2.intFirstSpouseID From Members2 Where Members2.intFirstSpouseID = Forms.frmMembers2.CurrentRecord.ID"
    
    
    Set rstSpouse1Query = currDB.OpenRecordset(strSQLFirst)
    'etc...
    I have also tried the following with the same result. Where am I going wrong?


    Code:
    strSQLFirst = "Select Members2.ID, Members2.intFirstSpouseID From Members2 Where Members2.intFirstSpouseID = Forms.frmMembers2.ID"
    and

    Code:
    strSQLFirst = "Select Members2.ID, Members2.intFirstSpouseID From Members2 Where Members2.intFirstSpouseID = Me.ID"

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    you can't just include the form reference as literal text when doing this in vba - unless you are altering the sql property of a query, which you are not.
    Try
    Code:
    Where Members2.intFirstSpouseID = & Forms.frmMembers2.CurrentRecord.ID
    unless the control holds text, in which case maybe

    Code:
    Where Members2.intFirstSpouseID = "'" & Forms.frmMembers2.CurrentRecord.ID & "'"
    I have a feeling that you will still have the same error. In that case, I'd declare a variable and make it equal the form control, then substitute the variable for the form reference in your sql statement build. Keep in mind that even with a variable, the correct concatenation is still required.
    Last edited by Micron; 03-29-2021 at 03:03 PM. Reason: added info
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    wvmitchell is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2020
    Posts
    24
    strSQLFirst = "Select Members2.ID, Members2.intFirstSpouseID From Members2 Where Members2.intFirstSpouseID = " & Forms.frmMembers2.ID

  4. #4
    drhansenjr is offline Novice
    Windows 10 Office 365
    Join Date
    Mar 2021
    Posts
    14
    Quote Originally Posted by drhansenjr View Post
    This is driving me nuts...

    I am trying to design a query within a form's Form_Current event code that returns the record ID and integer value of a field named "intFirstSpouseID" when a new record is selected in a combobox. I have tried a number of variations but each time get the error "Runtime error '3061': Too few parameters. Expected 1." on the OpenRecordset line The table name is "Members2" and the form name is "frmMembers2":




    Code:
    Private Sub Form_Current()
    
    
    Dim rstSpouse1Query As Recordset
    Dim currDB As Database
    Dim strSQLFirst As String
     
    Set currDB = CurrentDb
    strSQLFirst = "Select Members2.ID, Members2.intFirstSpouseID From Members2 Where Members2.intFirstSpouseID = Forms.frmMembers2.CurrentRecord.ID"
    
    
    Set rstSpouse1Query = currDB.OpenRecordset(strSQLFirst)
    'etc...
    I have also tried the following with the same result. Where am I going wrong?


    Code:
    strSQLFirst = "Select Members2.ID, Members2.intFirstSpouseID From Members2 Where Members2.intFirstSpouseID = Forms.frmMembers2.ID"
    and

    Code:
    strSQLFirst = "Select Members2.ID, Members2.intFirstSpouseID From Members2 Where Members2.intFirstSpouseID = Me.ID"


    A belated "thank you!" This did the trick.

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

Similar Threads

  1. Replies: 4
    Last Post: 11-19-2018, 03:26 PM
  2. Replies: 3
    Last Post: 07-30-2018, 05:45 PM
  3. Error 3061. Too few parameters. Expected 1.
    By Glenn_Suggs in forum Programming
    Replies: 5
    Last Post: 02-03-2015, 12:03 PM
  4. Runtime Error 3061. Too few parameters, expected 2
    By Gina Maylone in forum Programming
    Replies: 35
    Last Post: 01-13-2014, 02:37 PM
  5. Replies: 3
    Last Post: 04-26-2013, 01:37 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