Results 1 to 6 of 6
  1. #1
    stupesek is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Sep 2010
    Posts
    46

    Too few parameters error.

    Dim strDocName As String


    Dim strWhere As String
    Dim strQueryName As String

    strQueryName = "Date Reported Stamp"
    strDocName = "Irrigation Nitrate Report"

    CurrentDb.Execute strQueryName, dbFailOnError
    DoCmd.OpenReport strDocName, acViewPreview, , "ReportNumber Between " & Me.BegReport & " And " & Me.EndReport

    DoCmd.Close acForm, "Get Print Batch"

    In the above code I am getting a "Too few parameters. Expected 2." error message. The query date stamps a field in a table then opens the appropriate report. The error message doesn't tell me where the error lies.

    Thanks

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    My guess is that the query you're executing has 2 form references in it. The Execute method can't resolve form references. You can use OpenQuery instead or wrap the form references in the Eval() function.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    stupesek is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Sep 2010
    Posts
    46
    Can I put the same Where clause in the CurrentDb.Execute statement that is in the DoCmd.OpenReport below it?

  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,530
    Not really, if you mean what I think you mean. A typical way to use Execute with parameters is to concatenate their values in:

    CurrentDb.Execute "DELETE * FROM TableName WHERE FieldName = " & Me.TextboxName, dbFailOnError

    What is the query doing?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    stupesek is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Sep 2010
    Posts
    46
    The code is for a button on a form uses two text boxes to the beginning record to print and the ending record to print. The query stamps the date to a field when the report is first printed "[DateReported]". Then opens the reports that are between the beginning and ending report numbers to print. So the update query needs to have the same beginning and ending criteria. I also wish to suppress the pop-ups that confirm the user is about to update 'n' records.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    You can use

    DoCmd.SetWarnings False

    to turn off those warnings. Make sure to turn them back on after running the query.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 3
    Last Post: 07-01-2010, 07:55 PM
  2. Why am I getting error: too few parameters?
    By cowboy in forum Programming
    Replies: 3
    Last Post: 03-24-2010, 10:13 AM
  3. Report parameters
    By saylindara in forum Reports
    Replies: 15
    Last Post: 08-02-2009, 03:49 PM
  4. Parameters of all fields
    By seen123 in forum Import/Export Data
    Replies: 1
    Last Post: 02-20-2009, 02:50 PM
  5. Replies: 0
    Last Post: 02-15-2007, 03:07 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