Results 1 to 9 of 9
  1. #1
    PicoTTS is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2016
    Posts
    29

    Run-time Error: Too Few Parameters. Expect 1

    Hi,

    I am trying to open a query recordset but I am getting the following error: "Run-time error '3061': Too few parameters. Expected 1."

    I have the following code:

    Dim rst1 As DAO.Recordset
    Set rst1 = CurrentDb.OpenRecordset("SELECT * FROM [Product Info Query] WHERE [Job] = '" & [Job_Number] & "'")

    [Job_Number] is a string of text btw.

    I have a feeling it has to do with the fact that the query I am trying to refer to has "[Forms]![Order Info]![Job_Number]" as the criteria for [Job]. When I remove the criteria from the query, my lines of code works.



    Any ideas on why I am getting this error? When I hover over [Job_Number], it does yield the correct string I am trying to filter. Thanks

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    If that is the text box name, You can use:
    me.Job_Number
    or
    the entire path,
    forms![order info]!Job_number
    Or

    you have a misspelled item. Text box, field, or table.

  3. #3
    PicoTTS is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2016
    Posts
    29
    Yes [Job_Number] is the name of the control.

    Sorry I don't quite follow. What exactly am I changing?

    I have tried:

    Set rst1 = CurrentDb.OpenRecordset("SELECT * FROM [Product Info Query] WHERE [Job] = '" & Forms![Order Info]!Job_Number & "'")

    But that still gives me the "Run-time error '3061': Too few parameters. Expected 1." error. I am sure that everything is spelled correctly.

  4. #4
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    You were right the first time - it is the previous query, you cannot have parameters. Is it possible to combine the two queries into one SQL statement?

  5. #5
    PicoTTS is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2016
    Posts
    29
    I don't think I can change my original query because that query is used to populate a combobox dropdown list. I assume in this case that my only option is to create a second query without a parameter?

  6. #6
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Or, like I said, combine them into one SQL statement for use here. No need to change the original one. You are doing a SELECT * so it should be easy enough to change that to select the fields that you need.

    BTW, a combobox doesn't need a query, it can also be an SQL statement. Queries should only be created when absolutely necessary.

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    The simplest work-around is wrapping the form reference in the query in the Eval() function. Alternatively, you can use a DAO QueryDef, resolve the parameter, and open your recordset on the QueryDef:

    http://access.mvps.org/access/queries/qry0013.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    When you run that original Select to open the recordset, is the form open? If not, you will get that error.

    More importantly, your original Select statement doesn't make sense anyway. The query you are selecting from has criteria for [Job], but then you have another criteria clause for [Job] in the SQL for the recordset. I think that both are the same though, so removing the criteria from the query should solve the problem, as you saw. It should do just what you want to, because you are using the same criteria - but in the recordset SQL instead of the query.

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Quote Originally Posted by John_G View Post
    When you run that original Select to open the recordset, is the form open? If not, you will get that error.
    You'll get the error even if the form is open. As noted in the link I posted, OpenRecordset can't resolve the form reference in the underlying query.
    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: 4
    Last Post: 09-28-2016, 07:13 AM
  2. Replies: 5
    Last Post: 03-27-2015, 03:42 PM
  3. Chart Not acting as you would expect
    By techtony in forum Reports
    Replies: 8
    Last Post: 08-08-2014, 02:22 PM
  4. run time error-3061 too few parameters.
    By pervej.fac in forum Queries
    Replies: 1
    Last Post: 01-04-2014, 05:32 AM
  5. Replies: 1
    Last Post: 05-21-2011, 01:33 AM

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