Results 1 to 4 of 4
  1. #1
    markjkubicki's Avatar
    markjkubicki is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    496

    SQL results in the dreaded 3061 "Too few parameters, expected 1" error

    ...and I just can't get to why (to the point of frustration -which leads me to believe it's right under my keys...)

    Code:
          
                   Dim vOptionNumber As Long
                   Dim dbs As DAO.Database
                   Dim rst As DAO.Recordset
    
                   vOptionNumber = Nz([cmbInstallationNoteTitle], 0) + Nz([cmbInstallationNoteTitle_LongList], 0) 
                                           ' results in a valid number
                                          
                    strSQL = "SELECT * FROM [tbeInstallationNotes] WHERE [InstallationNote_OptionNumber] = vOptionNumber; " 
                                ' tbeInstallationNotes is a properly spelled valid table
                                ' InstallationNote_OptionNumber is a properly spelled field with a number data type
    
                                         
                    Set dbs = CurrentDb()
                    Set rst = dbs.OpenRecordset(strSQL)
                                 ' and of course this is where the error occurs
                        With rst
                        DoCmd.GoToRecord , "", acFirst
                        Do Until .EOF
                        <...>
    any suggestions at all will be greatly appreciated in advance,
    thnx
    mark

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You have to concatenate the variable into the string.

    strSQL = "SELECT * FROM [tbeInstallationNotes] WHERE [InstallationNote_OptionNumber] = " & vOptionNumber
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You MUST concatenate the number (vOptionNumber) to the SQL string.

    Try this - Add the line in BLUE (your code):
    Code:
                   Dim vOptionNumber As Long
                   Dim dbs As DAO.Database
                   Dim rst As DAO.Recordset
    
                   vOptionNumber = Nz([cmbInstallationNoteTitle], 0) + Nz([cmbInstallationNoteTitle_LongList], 0) 
                                           ' results in a valid number
                                          
                    strSQL = "SELECT * FROM [tbeInstallationNotes] WHERE [InstallationNote_OptionNumber] = vOptionNumber; " 
                                ' tbeInstallationNotes is a properly spelled valid table
                                ' InstallationNote_OptionNumber is a properly spelled field with a number data type
    
                   Debug.Print strSQL
    
                   'Set a breakpoint on the next line so you can see the immediate window
                    Set dbs = CurrentDb()
                    Set rst = dbs.OpenRecordset(strSQL)
                                 ' and of course this is where the error occurs
                        With rst
                        DoCmd.GoToRecord , "", acFirst
                        Do Until .EOF
                        <...>
    Look at the immediate window.

    Now change the code to this (modified code):
    Code:
                   Dim vOptionNumber As Long
                   Dim dbs As DAO.Database
                   Dim rst As DAO.Recordset
    
                   vOptionNumber = Nz([cmbInstallationNoteTitle], 0) + Nz([cmbInstallationNoteTitle_LongList], 0) 
                                           ' results in a valid number
                                          
                    strSQL = "SELECT * FROM [tbeInstallationNotes] WHERE [InstallationNote_OptionNumber] = " & vOptionNumber & ";" 
                                ' tbeInstallationNotes is a properly spelled valid table
                                ' InstallationNote_OptionNumber is a properly spelled field with a number data type
    
                   Debug.Print strSQL
    
                   'Set a breakpoint on the next line so you can see the immediate window                                     
                    Set dbs = CurrentDb()
                    Set rst = dbs.OpenRecordset(strSQL)
                                 ' and of course this is where the error occurs
                        With rst
                        DoCmd.GoToRecord , "", acFirst
                        Do Until .EOF
                        <...>
    Look at the immediate window. What is the difference???

  4. #4
    markjkubicki's Avatar
    markjkubicki is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Jul 2010
    Location
    Fire Island Pines, NY
    Posts
    496
    got it
    thnx (learn something new every day); (and sometimes something old... as long as "something is learned!)

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