Results 1 to 8 of 8
  1. #1
    uncletreetrunk is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Jul 2012
    Posts
    72

    Too Few Parameters, Error 3061

    Hi all,

    When I run the code below I get Run Time Error 3061, Too Few Parameters

    Also I was wondering can I concatenate a string to itself in vba like you can in java and c++?

    Code:
    strSQL = "INSERT INTO [To Be Added]([Program Name], [Program Number], [Project Name], [Project Number], Phase, Scope, [Board Action No], [Board Date], [Item Number], [Amount Requested], [Project Manager], [Spec No] ) VALUES('" & Forms!Add!ProgName & "', Forms!Add!ProgNum, '" & Forms!Add!ProjName & "', Forms!Add!ProjNum, '" & Forms!Add!Phase & "', '" & Forms!Add!Scope & "',  Forms!Add!BA ,#" & Forms!Add!BD & "#,'" & Forms!Add!Item & "', Forms!Add!Requested, '" & Forms!Add!PM & "', Forms!Add!Spec)"
    Thanks for your assistance!

  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,521
    Some of the form values are concatenated into the string, some aren't. They all need to be. For example:


    VALUES('" & Forms!Add!ProgName & "', Forms!Add!ProgNum, '" &

    ProgName is handled properly, ProgNum is not. This may help you:


    http://www.baldyweb.com/ImmediateWindow.htm

    You can certainly concatenate a string on itself, or use the more efficient line-continuation characters space-underscore:

    Code:
        strSQL = "SELECT ResNum, AuthBy, PassName " _
               & "FROM tblReservations " _
               & "WHERE Resnum = " & Me.ReservationNum
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    uncletreetrunk is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Jul 2012
    Posts
    72
    Thanks for the help! How do I concatenate a number into the string?

    That link helped alot. I stopped getting error 3061, unfortunately I'm getting 3134 now xD
    I'll have another look at it tomorrow before I post it up

    Oh so that's what those are, I've seen those on code sometimes and never understood.

  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,521
    This may help understand the concatenation.

    http://www.baldyweb.com/BuildSQL.htm

    I don't know what a 3134 error is offhand.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    uncletreetrunk is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Jul 2012
    Posts
    72
    Thanks for the link!
    No worries I wasn't expecting it haha that's wayyy to many error messages to memorize!
    Error 3134 Syntax Error in Insert Into statement.

    Code:
    strSQL1 = " INSERT INTO [To Be Added]([Program Name], [Program Number], [Project Name], [Project Number], Phase," & _
                "Scope, [Board Action No], [Board Date], [Item Number], [Amount Requested], [Project Manager], [Spec No])" & _
                "VALUES('" & Forms![Add Form]!ProgName & "', " & Forms![Add Form]!ProgNum & ", '" & Forms![Add Form]!ProjName & "', " & _
                "" & Forms![Add Form]!ProjNum & ", '" & Forms![Add Form]!Phase & "', '" & Forms![Add Form]!Scope & "', '" & Forms![Add Form]!BA & "' ," & _
                "#" & Forms![Add Form]!BD & "# ,'" & Forms![Add Form]!Item & "', " & Forms![Add Form]!Requested & ", " & _
                "'" & Forms![Add Form]!PM & "', " & Forms![Add Form]!Spec & " )"

  6. #6
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    To make the code easier to read (for me), I modified it a little.
    Code:
       strSql1 = " INSERT INTO [To Be Added]([Program Name], [Program Number], [Project Name], [Project Number], Phase,"
       strSql1 = strSql1 & " Scope, [Board Action No], [Board Date], [Item Number], [Amount Requested], [Project Manager], [Spec No])"
       strSql1 = strSql1 & " VALUES ('" & Forms![Add Form]!ProgName & "', " & Forms![Add Form]!ProgNum & ", '" & Forms![Add Form]!ProjName & "',"
       strSql1 = strSql1 & " " & Forms![Add Form]!ProjNum & ", '" & Forms![Add Form]!Phase & "', '" & Forms![Add Form]!Scope & "', '" & Forms![Add Form]!BA & "',"
       strSql1 = strSql1 & " #" & Forms![Add Form]!BD & "# ,'" & Forms![Add Form]![Item] & "', " & Forms![Add Form]!Requested & ","
       strSql1 = strSql1 & " '" & Forms![Add Form]!PM & "', " & Forms![Add Form]!Spec & " );"
       
       Debug.Print strSql1
    I added brackets around "ITEM" - it is a reserved word (and shouldn't be used for object names). Set a breakpoint on the debug line. Copy the line from the immediate window and paste it into Notepad. Check to ensure the fields/values/delimiters are correct. Also check that spaces are in the proper place.

    Also.... it is not advisable to use spaces in object names. Major source of headaches.........

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Use the technique in post 2 and post the finished SQL here if you don't spot the problem.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    uncletreetrunk is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Jul 2012
    Posts
    72
    @ssanfu ohh thanks, didn't know that was a reserve word. still learning my way around access.

    @pbaldy I was using the immediate window and everything was looking fine. so I double checked the table field types and they did not match *facepalm*

    Thanks so much for the help guys!

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

Similar Threads

  1. Error 3061 Too Few parameters
    By gopherking in forum Programming
    Replies: 5
    Last Post: 10-06-2011, 11:50 AM
  2. 3061 Error. Too few parameters. Expected 1.
    By rghollenbeck in forum Queries
    Replies: 5
    Last Post: 09-28-2011, 12:12 PM
  3. Replies: 1
    Last Post: 05-21-2011, 01:33 AM
  4. Error 3061 Too Few Parameters Expecting 1
    By ironman in forum Programming
    Replies: 4
    Last Post: 05-09-2011, 03:20 PM
  5. Error 3061
    By Shanks in forum Queries
    Replies: 4
    Last Post: 09-16-2009, 07:13 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