Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2008
    Posts
    9

    Question CurrentDB.Execute: Too few parameters

    Hello, all!


    I'm using Access 2002, and I'm running into an issue with using CurrentDB.Execute to run an 'append' query. My code is simply this:

    Code:
    strQueryName = "qry_20_AvgInboundPieces_Monthly_3Count"
    CurrentDb.Execute strQueryName, dbFailOnError
    When I run it, it gives me this error:

    Run-time error '3061':
    Too few parameters. Expected 2.

    I've verified that the query works by running it other ways. I can double-click on it and it fires off just fine, and it plays nice with DoCmd.OpenQuery. I'm trying to get away from DoCmd.OpenQuery because of having to use SetWarnings False/True to make it not ask me if I'm sure I want to update the table when the query runs. I have read several suggestions other places saying to use CurrentDb.Execute instead, but I cannot get it to work. I've tried it without the dbFailOnError, and I've tried these, both with and without dbFailOnError:

    Code:
    strQueryName = "qry_20_AvgInboundPieces_Monthly_3Count"
    CurrentDb.QueryDefs(strQueryName).Execute dbFailOnError
    
    CurrentDb.QueryDefs("qry_20_AvgInboundPieces_Monthly_3Count").Execute dbFailOnError
    I'm not sure if this makes any difference, but the query that's trying to run does pull some date data for SQL comparisons from form fields. I've set the form field types to "General Date". I'm not sure if that's correct since some of them have date/time info (9/6/2008 12:00:00AM) and others just have the date (9/6/2008). I've also tried adding the following to the beginning of the SQL itself to see if that made a difference, but it didn't.

    Code:
    "PARAMETERS [Forms]![frmMain]![txtMonthBegin] DateTime, [Forms]![frmMain]![txtMonthEnd] DateTime;"
    Other than that, the code seems pretty straight forward, and the query seems to run using just about everything else, so I don't see why it won't run here. Does anyone have any suggestions?

    Thanks,
    Jeremy
    Last edited by thinker5555; 09-06-08 at 12:46.

  2. #2
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,910
    Quote Originally Posted by thinker5555
    I'm not sure if this makes any difference, but the query that's trying to run does pull some date data for SQL comparisons from form fields
    Yeah - that makes every difference. You add parameters to the query, and instantiate DAO some parameter objects in your code and use these to pass the values to the query via the querydef object.

    I haven't done it for years so can't be much more specific but the above should give you enough to google around - come back if you don't crack it.
    Testimonial:
    pootle flump
    ur codings are working excelent.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •