Results 1 to 5 of 5
  1. #1
    Ganymede is offline Competent Performer
    Windows 7 64bit Access 2016
    Join Date
    Dec 2011
    Posts
    116

    CurrentDb.Execute [Delete Query] -> "Too few parameters. Expected 1."

    I have a delete query called "Query2". I want to run Query2 without it displaying any of those warning messages (e.g., you are about to delete 1 record, etc.). I udnerstand that the CurrentDB.Execute function will run the query without any of those warnings. But I can't seem to get it to work. When I run this code, I get Run-time error 3061 "Too Few parameters. Expected 1."

    Code:
    CurrentDb.Execute ("Query2"), dbFailOnError
    I have searched exhaustively for a solution to no avail. Any assitance would be greatly appreciated.

  2. #2
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    This is a very common topic in the Access world, your query probably makes reference to a form control(s) and VBA cannot resolve that. You can try to wrap those (in the Query2 design view) with the Eval() function and see if it works or use the qdf.Execute method of the QueryDef object:
    Code:
    Dim qdf as DAO.QueryDef, db as DAO.database, prm as Parameter
    
    Set db=CurrentDb
    Set qdf = CurrentDb.QueryDefs("Query2")
    
    For Each prm In qdf.Parameters
         prm.Value = Eval(prm.Name)
    Next prm
    
    qdf.Execute dbFailOnError
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,569
    Quote Originally Posted by Ganymede View Post
    I have a delete query called "Query2". I want to run Query2 without it displaying any of those warning messages (e.g., you are about to delete 1 record, etc.). I udnerstand that the CurrentDB.Execute function will run the query without any of those warnings. But I can't seem to get it to work. When I run this code, I get Run-time error 3061 "Too Few parameters. Expected 1."

    Code:
    CurrentDb.Execute ("Query2"), dbFailOnError
    I have searched exhaustively for a solution to no avail. Any assitance would be greatly appreciated.
    And you cannot show the sql for that query?
    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

  4. #4
    Ganymede is offline Competent Performer
    Windows 7 64bit Access 2016
    Join Date
    Dec 2011
    Posts
    116
    Quote Originally Posted by Gicu View Post
    This is a very common topic in the Access world, your query probably makes reference to a form control(s) and VBA cannot resolve that. You can try to wrap those (in the Query2 design view) with the Eval() function and see if it works or use the qdf.Execute method of the QueryDef object:
    Code:
    Dim qdf as DAO.QueryDef, db as DAO.database, prm as Parameter
    
    Set db=CurrentDb
    Set qdf = CurrentDb.QueryDefs("Query2")
    
    For Each prm In qdf.Parameters
         prm.Value = Eval(prm.Name)
    Next prm
    
    qdf.Execute dbFailOnError
    Cheers,
    Thank you! This is helpful!

  5. #5
    Ganymede is offline Competent Performer
    Windows 7 64bit Access 2016
    Join Date
    Dec 2011
    Posts
    116
    Quote Originally Posted by Welshgasman View Post
    And you cannot show the sql for that query?
    Sorry about that. It didn't occur to me that the query code itself could be the problem. But I think Gicu's post sorted that out for me. He was right. The query referenced a form control.

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

Similar Threads

  1. Replies: 18
    Last Post: 10-17-2022, 06:13 AM
  2. Replies: 3
    Last Post: 07-30-2018, 05:45 PM
  3. Too few parameters error on CurrentDb.OpenRecordset
    By hfreedman1957 in forum Programming
    Replies: 4
    Last Post: 05-12-2017, 08:45 PM
  4. Query has "Too Few Parameters - Expected 6"
    By Paul H in forum Queries
    Replies: 9
    Last Post: 11-18-2015, 01:00 PM
  5. Execute, "Too few parameters", "Expected 2"
    By jhrBanker in forum Forms
    Replies: 3
    Last Post: 10-30-2014, 02:18 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