Results 1 to 5 of 5

Thread: Query Trouble

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2003
    Posts
    117

    Query Trouble

    Hi, when I call rs.open I get the error: Too few parameters, Expected 1.

    VB Code:
    1. Dim cn As ADODB.Connection
    2.     Dim rs As ADODB.Recordset
    3.     Dim sql As String
    4.     Dim cboText As String
    5.    
    6.     Set cn = New ADODB.Connection
    7.     cn.ConnectionString = "Driver={Microsoft Access Driver (*.mdb)};" & _
    8.            "Dbq=h:\project\db1.mdb;" & _
    9.            "Uid=admin;" & _
    10.            "Pwd="
    11.     cn.Open
    12.     Set rs = New ADODB.Recordset
    13.     cboText = cboClass.Text
    14.     sql = "SELECT StudentName FROM tblStudents WHERE " & _
    15.                                 "StudentClass1 = " & Quotes(cboText) & " OR " & _
    16.                                 "StudentClass2 = " & Quotes(cboText) & " OR " & _
    17.                                 "StudentClass3 = " & Quotes(cboText) & " OR " & _
    18.                                 "StudentClass4 = " & Quotes(cboText) & " OR " & _
    19.                                 "StudentClass5 = " & Quotes(cboText) & " OR " & _
    20.                                 "StudentClass6 = " & Quotes(cboText) & " OR " & _
    21.                                 "StudentClass7 = " & Quotes(cboText) & " OR " & _
    22.                                 "StudentClass8 = " & Quotes(cboText) & " OR " & _
    23.                                 "StudentClass9 = " & Quotes(cboText) & " OR " & _
    24.                                 "StudentClass10 = " & Quotes(cboText)
    25.     MsgBox sql
    26.     rs.Open sql, cn2
    27.     rs.MoveFirst
    28.     Do While Not rs.EOF

    Any ideas?
    Last edited by ironhide; Feb 12th, 2004 at 08:07 PM.

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    The usuall culprits for this error -

    One of the database field names is misspelled.

    Character data is not surrounded with single quotes.

    VB Code:
    1. "StudentClass1 = '" & Quotes(cboText) & "' OR " & _

  3. #3
    Fanatic Member
    Join Date
    Sep 2000
    Location
    Over There
    Posts
    522
    Originally posted by brucevde
    The usuall culprits for this error -

    One of the database field names is misspelled.

    Character data is not surrounded with single quotes.

    VB Code:
    1. "StudentClass1 = '" & Quotes(cboText) & "' OR " & _
    since he's using access, doesn't he need to use double quotes??
    simplest thing to do is debug.print sql and post it.
    or you may find the problem.
    It Never Fails. Everytime I try to make a program idiot proof, the world makes a better idiot.

  4. #4
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    since he's using access, doesn't he need to use double quotes??
    Nope.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Feb 2003
    Posts
    117
    The sql is statement is (using debug.print)
    SELECT StudentName FROM tblStudents WHERE StudentClass1 = "12SDD" OR StudentClass2 = "12SDD" OR StudentClass3 = "12SDD" OR StudentClass4 = "12SDD" OR StudentClass5 = "12SDD" OR StudentClass6 = "12SDD" OR StudentClass7 = "12SDD" OR StudentClass8 = "12SDD" OR StudentClass9 = "12SDD" OR StudentClass10 = "12SDD"

    When calling rs.open still gives me the too FEW ?? parameters, expected one...

    Any help?

    Ta.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width