Results 1 to 8 of 8
  1. #1
    mlrucci is offline Competent Performer
    Windows 7 64bit Office 365
    Join Date
    Apr 2018
    Posts
    202

    Runtime Error 3061

    Good morning, I am a bit confused. I have vba code to run an append qry upon pressing a button on a form. (the code is in a qry not vba sql) For some reason, I am getting Runtime error 3061 Too few parameters. Expected 2
    Here is the code.
    Code:
    INSERT INTO tblAppImportFM_ConCon ( ProductID )
    SELECT tblImportFM_ConCon.CalcType AS ProductID
    FROM tblImportFM_ConCon
    WHERE (((tblImportFM_ConCon.CalcType)=37) AND ((tblImportFM_ConCon.[CC Application Date]) Between [Forms]![frmImportFM_ConCon]![dtInvoiceFirst] And [Forms]![frmImportFM_ConCon]![dtInvoiceLast]));
    Here is the funny thing which is throwing me off, if I execute the append qry without going through VBA, it works great. Using the form to execute the append qry gives me the error. The form with the date range is open. Not sure where the problem is located. Any help would be appreciated.

    Thank you

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Is frmImportFM_ConCon open ?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    mlrucci is offline Competent Performer
    Windows 7 64bit Office 365
    Join Date
    Apr 2018
    Posts
    202
    Yes. I even tried to move the location to another open form to see if it was corrupt Weird!!!

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    what VBA code are you using to execute the query? .execute? .runsql?

    could be wrong but seem to recall that with one of them the query can't include parameters such as your form references

  5. #5
    mlrucci is offline Competent Performer
    Windows 7 64bit Office 365
    Join Date
    Apr 2018
    Posts
    202
    I am using execute. Let me try to do it via sql

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    I know there are ssues when you use the query in a recordset?
    https://www.access-programmers.co.uk.../#post-1653079

    However I thought form controls in a query were fine, though I tended to use tempvars ?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  7. #7
    mlrucci is offline Competent Performer
    Windows 7 64bit Office 365
    Join Date
    Apr 2018
    Posts
    202
    That was it!! I converted the qry to sql and executed the append qry in vba. Works perfectly. Thanks for the insight!!!

  8. #8
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Hmm, I didn't chime in because you said
    (the code is in a qry not vba sql)
    but now say
    I converted the qry to sql
    Access queries are based on a sql syntax (albeit specific to Access). I think you meant you had formed a sql statement and were trying to execute it using vba? Code sql statements are not processed by the same part of Access so you cannot use things like Forms!frmMain... without concatenation. That is, such object references cannot be part of the literal string that comprises actual sql.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Runtime error 3061
    By DMT Dave in forum Access
    Replies: 3
    Last Post: 01-15-2019, 01:39 PM
  2. Runtime error 3061
    By caniread in forum Programming
    Replies: 7
    Last Post: 01-31-2017, 05:07 PM
  3. Replies: 3
    Last Post: 02-26-2016, 12:34 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. Runtime Error 3061 Expected 3
    By kumail123 in forum Programming
    Replies: 1
    Last Post: 03-28-2012, 09:44 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