Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1
    JimFlood7898 is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2020
    Posts
    13

    Error 3061 Two Few Parameter Expected 2

    I kind of know what the problem is, I have code to export a query to excel spread sheet, got the code and lessons from a site "Access Jitsu", got the code working good until I added the "Between Dates" criteria in the query. Without the date criteria it works great. I'm sure I have to add this to the SQL line, but don't know how.



    This is what I have and everything works until I add the DateReceipt range: Between [Forms]![pfrm_ExpenseSelectRpt].[cboStartDate] And [Forms]![pfrm_ExpenseSelectRpt].[cboEndDate]

    SQL = "SELECT NoOrder, DateReceipt, Amount, VenderStore, CostCode, Description, Project, ReceiptYN, Explain " & "FROM qry_ReportExpenseRange " & "ORDER BY DateReceipt "

    Any help would be appreciated. Not an expert by no means, construction worker, but love access, it does a lot once it's done.

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    try

    Code:
    SQL = "SELECT NoOrder, DateReceipt, Amount, VenderStore, CostCode, Description, Project, ReceiptYN, Explain" & _
              " FROM qry_ReportExpenseRange " & _
              " WHERE DateReceipt Between " & format([Forms]![pfrm_ExpenseSelectRpt].[cboStartDate],"mm/dd/yyyy") & " AND " & format([Forms]![pfrm_ExpenseSelectRpt].[cboEndDate],"mm/dd/yyyy") & _
              " ORDER BY DateReceipt"

  3. #3
    JimFlood7898 is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2020
    Posts
    13
    Thanks for the quick reply, put the code in and now it says: Error Number 2450=Microsft Access cannot find the refererencd form 'pfrm_ExpenseSelectRpt.
    Think I need to keep the form open until after the export. Will work on it tomorrow.

  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,521
    You do need to keep the form open. Also, presuming the data type is date/time, you need delimiters:

    Code:
    SQL = "SELECT NoOrder, DateReceipt, Amount, VenderStore, CostCode, Description, Project, ReceiptYN, Explain" & _
              " FROM qry_ReportExpenseRange " & _
              " WHERE DateReceipt Between #" & format([Forms]![pfrm_ExpenseSelectRpt].[cboStartDate],"mm/dd/yyyy") & "# AND #" & format([Forms]![pfrm_ExpenseSelectRpt].[cboEndDate],"mm/dd/yyyy") & _
              "# ORDER BY DateReceipt"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    thanks for the correction - forgot about the #

  6. #6
    JimFlood7898 is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2020
    Posts
    13
    Tried:
    SQL = "SELECT NoOrder, DateReceipt, Amount, VenderStore, CostCode, Description, Project, ReceiptYN, Explain" & _
    " FROM qry_ReportExpenseRange " & _
    " WHERE D
    ateReceipt
    Between
    #
    " & format([Forms]![pfrm_ExpenseSelectRpt].[cboStartDate],"mm/dd/yyyy") & "
    #
    AND
    #
    " & format([Forms]![pfrm_ExpenseSelectRpt].[cboEndDate],"mm/dd/yyyy") & _
    "
    #
    ORDER BY DateReceipt"

    But still comes up with Error 3061 Too Few Parameters, Expected 2

  7. #7
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    is [Forms]![pfrm_ExpenseSelectRpt] open? are the fields populated?

  8. #8
    JimFlood7898 is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2020
    Posts
    13
    Posting the full SQL from the Query that the Sub is based on

    SELECT qry_Expenses.NoOrder, qry_Expenses.DateReceipt, qry_Expenses.Amount, qry_Expenses.VenderStore, tbl_ExpenseCodes.CostCode, qry_Expenses.Description, [ProjectNumber] & " " & [ProjectTitle] AS Project, qry_Expenses.ReceiptYN, qry_Expenses.Explain, qry_Expenses.MethodPay, qry_Expenses.SelectReceipt
    FROM tbl_ExpenseCodes INNER JOIN (((qry_TimeShtWk INNER JOIN qry_TimeShtProj ON qry_TimeShtWk.TimeShtWk_ID = qry_TimeShtProj.TimeShtWk_ID) INNER JOIN qry_Projects ON qry_TimeShtProj.[Project_ID] = qry_Projects.Project_ID) INNER JOIN qry_Expenses ON qry_TimeShtProj.TimeShtProj_ID = qry_Expenses.TimeShtProj_ID) ON tbl_ExpenseCodes.CostCode_ID = qry_Expenses.CostCode
    WHERE (((qry_Expenses.DateReceipt) Between [StartDate] And [EndDate]) AND ((qry_Expenses.MethodPay) Like "BIC*" Or (qry_Expenses.MethodPay) Like "Kwest*"));

    Tried pasting all this in the Sub, but that doesn't work.

  9. #9
    JimFlood7898 is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2020
    Posts
    13
    I went back and pasted the following SQL in the Sub OnClick. This works great, with all the other code to open and format the excel sheet.
    But I really need the Between Date criteria.

    SQL = "SELECT NoOrder, DateReceipt, Amount, VenderStore, CostCode, Description, Project, ReceiptYN, Explain " & "FROM qry_ReportExpenseRange " & "ORDER BY DateReceipt "

  10. #10
    JimFlood7898 is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2020
    Posts
    13
    Yes I had a popup form and left it open with a button to run the code to export.

  11. #11
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I think the date prompts need to be changed so they come from the/a form as well.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  12. #12
    JimFlood7898 is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2020
    Posts
    13
    "Removed the Order by and the Format date, trying to clean it and make it simply to work on it.
    This is what I have:
    SQL = "SELECT NoOrder, DateReceipt, Amount, VenderStore, CostCode, Description, Project, ReceiptYN, Explain" & " FROM qry_ReportExpenseRange " & _
    "WHERE DateReceipt Between #" & [Forms]![pfrm_ExpenseSelectRpt].[cboStartDate] & " # AND # " & [Forms]![pfrm_ExpenseSelectRpt].[cboEndDate]

    Ran the PopUp form and got this Error message:

    ErrorNumber: 3075= Syntax error in date in query expression DateReceipt Between #1/6/2020# AND # 2/17/2020


  13. #13
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Your error points out the problems. You've got spaces between the date and the #, and no # at the end.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  14. #14
    JimFlood7898 is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2020
    Posts
    13
    Change it to the following:
    SQL = "SELECT NoOrder, DateReceipt, Amount, VenderStore, CostCode, Description, Project, ReceiptYN, Explain" & " FROM qry_ReportExpenseRange " & _
    "WHERE DateReceipt Between #" & [Forms]![pfrm_ExpenseSelectRpt].[cboStartDate] & "# AND #" & [Forms]![pfrm_ExpenseSelectRpt].[cboEndDate] & "#"

    Now I'm back to: Error Number3061- Too few parameters, Expected 2


  15. #15
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Is the form open and the date combos filled in? Oh, and does the underlying query have any parameters that aren't being resolved?

    I'd typically use textboxes for dates, but you know your situation.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Macro Error 3061 Expected 5
    By Tamara Ghoussoub in forum Macros
    Replies: 2
    Last Post: 07-02-2018, 09:03 AM
  2. Error 3061. Too few parameters. Expected 1.
    By Glenn_Suggs in forum Programming
    Replies: 5
    Last Post: 02-03-2015, 12:03 PM
  3. Replies: 3
    Last Post: 04-26-2013, 01:37 PM
  4. Runtime Error 3061 Expected 3
    By kumail123 in forum Programming
    Replies: 1
    Last Post: 03-28-2012, 09:44 AM
  5. 3061 Error. Too few parameters. Expected 1.
    By rghollenbeck in forum Queries
    Replies: 5
    Last Post: 09-28-2011, 12:12 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