Too Few Parameters Expected N

If you’re working with ActiveX Data Objects (ADO) and connecting to a Jet database, you may get this error. One possible cause is that you misspelled a column name. When Jet encounters an unrecognized column name, it assumes it’s a parameter. Check the spelling of the field names in your SELECT statement.

Another possible cause, and one I experienced today, is surrounding strings in your WHERE clause with double quotes – it needs to be single quotes. Mine was fairly easy to track down because the error was “Too Few Parameters, Expected 3?. My SELECT statement started like this:

<span class="text">SELECT * FROM salesorder...</span>

so I knew I hadn’t spelled any column names wrong. I also knew I had five variables in my WHERE clause; three Strings and two Dates. I figured the problem must be in the Strings and it was.

sWhere = sWhere & ” (CustomerRef_ListID=’” & gsREPAIRCUSTID & “‘)”

5 Comments

  1. Mike M. says:

    Yeah…I had something like this a couple of years back. I was trying to connect to an Access database via VBA. I posted the problem in the excel.programming newsgroup and those that responded at that time were stumped as well. I think I picked it up through trial and error.

  2. doco says:

    I have long since just got into the habit of WHERE(((stringField)=” & PadQuotes(myStringValue) & “));”

    Public Function PadQuotes(ByVal szBareString As String) As String

        PadQuotes = Chr(34) &amp; szBareString &amp; Chr(34)

    End Function

  3. Jan says:

    As Doco shows it doesn’t really matter what the quotes are single or double. I prefer single to make it easier to read in vba, but the worst of all are irish names. They always catch me out.

  4. Jan: I used double quotes and I got the error. Then I switched to single quotes and it worked.

  5. Mani says:

    Thanks! My problem resolved because of you peoples….

Leave a Reply