none
access error too few parameters RRS feed

  • Question

  • Hello, I'm pretty new to access and SQl and I was wondering if someone could help me with this error I'm having where I type this code:

    query="SELECT [2009 Roster].*" & _
            "FROM [2009 Roster]" & _
            "WHERE ((([2009 Roster].[ID #])=IDNumberStoredAsString));"

    Set rst = database.OpenRecordset(query)

    And get the error two few parameters. expected 1.

    rst is a DAO.Recordset.

    I checked and made sure that every field matches an existing one, etc and types match in my where statement.  Am I missing something?

    Thanks.

    • Moved by VMazur Monday, July 19, 2010 10:26 AM Post related DAO technology, not to .NET (From:ADO.NET Managed Providers)
    Friday, July 16, 2010 2:31 PM

Answers

  • When your SQL query is parsed, IDNumberStoredAsString will be evaluated as a column name. I'm assuming that this is a variable containing a string value, so it needs to be evaluated prior to being passed to the database engine layer. See the below syntax:

    query="SELECT [2009 Roster].* " & _
        "FROM [2009 Roster] " & _
        "WHERE ((([2009 Roster].[ID #])='" & IDNumberStoredAsString & "'));"


    Paul ~~~~ Microsoft MVP (Visual Basic)
    • Marked as answer by etk1220 Friday, July 23, 2010 9:46 PM
    Friday, July 16, 2010 4:20 PM

All replies

  • too*
    Friday, July 16, 2010 2:54 PM
  • When your SQL query is parsed, IDNumberStoredAsString will be evaluated as a column name. I'm assuming that this is a variable containing a string value, so it needs to be evaluated prior to being passed to the database engine layer. See the below syntax:

    query="SELECT [2009 Roster].* " & _
        "FROM [2009 Roster] " & _
        "WHERE ((([2009 Roster].[ID #])='" & IDNumberStoredAsString & "'));"


    Paul ~~~~ Microsoft MVP (Visual Basic)
    • Marked as answer by etk1220 Friday, July 23, 2010 9:46 PM
    Friday, July 16, 2010 4:20 PM