Results 1 to 6 of 6
  1. #1
    RonL is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Location
    NJ
    Posts
    114

    Run time error 3061- Too few parameters, expected 1- VBA

    Hello all. The following code fragment is giving the subject error on the execute line. There are lots of posts about this sort of thing,
    and I guess I'm missing some simple syntactical point, but have wasted a lot of time moving quote marks around, etc. For info, the "x" is actually a placemark for a


    string variable, but I tried to simplify to a one letter literal to find the error; made no difference. The string looks right in the msgbox - ie. all variables have the correct values - this was true even when the "x" was the intended variable - and the field names are all spelled correctly.

    Would appreciate any help. Would also appreciate a link to a simple, surefire method of constructing these SQL strings for VBA.

    Thanks, Ron


    Code:
    strSQL = ""
    strSQL = "INSERT INTO tblShotList (ShootsFK, ShotNumber, ShotNumSuffix, fldOrderBy)" _
    & " Values (" & varShootsFK & "," & varShotNum & ", x," & varCurRecOrderBy + 1 & ");"
    MsgBox ("The insert string is: " & strSQL)
    CurrentDb.Execute strSQL, dbFailOnError[   ' <=gives 3061 error

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Does it work if you try:
    Code:
    DoCmd.RunSQL strSQL
    instead?

    I have come across instances in which that works, and the Execute method does not.

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    For info, the "x" is actually a placemark for a string variable,
    You need to delimit the text string with single quotes. And you should to concantate "X".

    Try:
    Code:
    strSQL = ""
    strSQL = "INSERT INTO tblShotList (ShootsFK, ShotNumber, ShotNumSuffix, fldOrderBy)"_
      & " VALUES (" & varShootsFK & ", " & varShotNum & ", '" & X & "', " & varCurRecOrderBy + 1 & ");"
    MsgBox ("The insert string is: " & strSQL)
    CurrentDb.Execute strSQL, dbFailOnError[   ' <=gives 3061 error
    Expanded, the red text is & ", ' " & X & " ', " &

  4. #4
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Good catch, Steve. I missed that.

  5. #5
    RonL is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Location
    NJ
    Posts
    114
    Thanks Steve, but that leaves the X as an undefined variable, not a string. I think I understand the principle, but I don't really understand the single vs. double quote business. As mentioned, the code I posted appears to evaluate properly. Will keep playing with it.

    EDIT - Oh wait - you meant to substitute my original string variable back in for the X. Yes!! It works. Thank you, thank you. (Still gotta understand this quote stuff.)

    Thx to you both, Ron

  6. #6
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Here is a beginning tutorial on Access.
    See Chapter 7 on delimiters. String and Dates require delimiters. Numbers do not require delimiters.
    (The other chapters are also worth a read.)

    Access Basics By Crystal
    http://www.accessmvp.com/strive4peace/Index.htm

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

Similar Threads

  1. Error 3061. Too few parameters. Expected 1.
    By Glenn_Suggs in forum Programming
    Replies: 5
    Last Post: 02-03-2015, 12:03 PM
  2. Runtime Error 3061. Too few parameters, expected 2
    By Gina Maylone in forum Programming
    Replies: 35
    Last Post: 01-13-2014, 02:37 PM
  3. Replies: 3
    Last Post: 04-26-2013, 01:37 PM
  4. 3061 Error. Too few parameters. Expected 1.
    By rghollenbeck in forum Queries
    Replies: 5
    Last Post: 09-28-2011, 12:12 PM
  5. Replies: 1
    Last Post: 05-21-2011, 01:33 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