Results 1 to 8 of 8
  1. #1
    klnlsu is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Apr 2015
    Posts
    107

    Getting parameter error when trying to open query as a DAO recordset

    I am trying to open a query as a recordset. Can someone please check my code below and see if I have an error?

    DoCmd.RunSQL "DELETE * FROM tblAllocations"
    Dim rsFGs As DAO.Recordset
    Dim rsBOM As DAO.Recordset
    Dim rsAllocsData As DAO.Recordset
    Set rsFGs = CurrentDb.OpenRecordset("SELECT * FROM qryOpenALLAllocationsSummary", dbOpenDynaset)
    Set rsBOM = CurrentDb.OpenRecordset("SELECT * FROM dbo_BMPRDSTR_SQL ORDER BY item_no, seq_no", dbOpenDynaset)


    Set rsAllocsData = CurrentDb.OpenRecordset("SELECT * FROM tblAllocations", dbOpenDynaset)

    I get an error that says "Run-time error '3061': Too few parameters. Expected 2." on the line that is in bold.

    Is there something wrong with my code? Could there be something in my query that is causing this?

  2. #2
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,165
    Code looks fine. Maybe double check your spelling of the query name? And go back into that query and double check that all the field names in it are correct... Does the query itself run without error when you open it via the navigation pane ?

    https://stackoverflow.com/questions/...-1-access-2007

  3. #3
    klnlsu is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Apr 2015
    Posts
    107
    The query runs and the spelling is correct. The query is an aggregate query that sums totals from three other queries that are in a UNION query. The three queries that are "unionized" use fields in an open form as criteria. The form is open when I run the code. I don't know if any of this information is helpful, but I thought I might should mention it.

  4. #4
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,165
    Quote Originally Posted by klnlsu View Post
    ... The three queries that are "unionized" use fields in an open form as criteria....
    I don't know. But check out the answer from "John Doe" on Mar 22 here: https://stackoverflow.com/questions/...-1-access-2007

  5. #5
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,165
    Quote Originally Posted by klnlsu View Post
    ... The three queries that are "unionized" use fields in an open form as criteria. The form is open when I run the code. I don't know if any of this information is helpful, but I thought I might should mention it.
    I did a little test and found that the params referring to the forms are indeed the problem.

    And I also found some solutions for you here: https://www.devhut.net/2011/11/07/ms...-query-in-vba/

  6. #6
    klnlsu is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Apr 2015
    Posts
    107
    Thanks for the link above! That worked! I simply changed the criteria syntax in my three queries to include the EVAL function and the VBA coding worked.

    Example:

    my query criteria was: <=[forms]![frmOrderHeaderEntry]![ShipDateTxt]

    and I changed it to: <=Eval("[forms]![frmOrderHeaderEntry]![ShipDateTxt]")

    That's all there was to it!

    Thanks again!

  7. #7
    nggman is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Oct 2017
    Posts
    27
    I am having a similar issue. [Enter Start Date] is one of my parameters.

    <=Eval("[forms]![frmOrderHeaderEntry]![ShipDateTxt]")

    For this line, what are you using for 'forms' and 'frmOrderHeaderEntry'?

    I am just trying this and it is not working. Eval("[Enter Start Date]")

  8. #8
    klnlsu is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Apr 2015
    Posts
    107
    Quote Originally Posted by nggman View Post
    I am having a similar issue. [Enter Start Date] is one of my parameters.

    <=Eval("[forms]![frmOrderHeaderEntry]![ShipDateTxt]")

    For this line, what are you using for 'forms' and 'frmOrderHeaderEntry'?

    I am just trying this and it is not working. Eval("[Enter Start Date]")
    I am looking at the data in a textbox (ShipDateTxt) on an open form (frmOrderHeaderEntry). I have not tried the EVAL function on a data prompt.

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

Similar Threads

  1. Recordset Given too few parameter error
    By boywonder381 in forum Programming
    Replies: 1
    Last Post: 11-11-2014, 12:07 AM
  2. Recordset Open Error
    By RayMilhon in forum Programming
    Replies: 4
    Last Post: 08-27-2013, 05:54 PM
  3. Replies: 2
    Last Post: 08-07-2013, 07:44 AM
  4. Replies: 3
    Last Post: 03-06-2013, 03:52 PM
  5. recordset open error on SQL query
    By Siuxia in forum Programming
    Replies: 5
    Last Post: 05-30-2012, 08:02 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