Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2005
    Location
    Nanded, India
    Posts
    397

    Unanswered: Too Few Parameters. Expected 1.

    Hi,

    What might the wrong with below code? Why its producing above error. It stops at set rst=....

    Dim db As Database
    Dim rst As Recordset

    Set rst = CurrentDb.OpenRecordset("Select * From T_Peter where StudentRollNo = '" & cboStudentRollNo & "'")

    Tbl T_Peter contains only 3-4 fields and StudentRollNo is text data type field.

    The CboStudentRollNo data source is some other table where there are student roll numbers. I m picking up roll numbers and puting into unbound text box called StudentRollNo. All text boxes on the forms are unbound.

    The above code is triggered when clicked the Save command button.

    Can somebody help me?
    With kind regards,
    Ashfaque

  2. #2
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Use a variable, assign the SQL statement to the variable, debug.print. Look at the statement.

    Forgive me - but you've been around here now for some time now - surely you know this is always the first step in debugging dynamic sql statements? If they don't work then step 1 has to be find out exectly what is actually getting executed.
    Testimonial:
    pootle flump
    ur codings are working excelent.

  3. #3
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Nice new name... but be careful... to shorten your name, someone might use:

    TALC-POOF 3

    LOOOL

    Aaaaanywaaay... why DIM DB as Database if you use CurrentDB ^^

    And if your "some other table" is an SQL server type table you might have to specify the extra parameters of the OpenRecordset() function. See help for details
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  4. #4
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Quote Originally Posted by StarTrekker
    Nice new name... but be careful... to shorten your name, someone might use:

    TALC-POOF 3

    LOOOL
    Oh...... smeg
    Testimonial:
    pootle flump
    ur codings are working excelent.

  5. #5
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Quote Originally Posted by StarTrekker
    Nice new name... but be careful... to shorten your name, someone might use:

    TALC-POOF 3

    LOOOL
    StarTrekker,

    Thank you, you're a genius!
    George
    Home | Blog

  6. #6
    Join Date
    Feb 2004
    Location
    Chicago, IL
    Posts
    1,312
    My experience is that Too few parameters is a typo in the field name or the field does not exist in the query or table.

    I would make sure the StudentRollNo field is in the T_Peter table/query.

  7. #7
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    You could try:

    Set rst = CurrentDb.OpenRecordset("Select * From T_Peter where StudentRollNo Like " " " & cboStudentRollNo & " " " ")

    (Note that I spaced out the " to show syntax - I've had pretty good luck using the 3 " at times regardless if it's numeric or string.)

    But that usually doesn't give you a parameter error which as DCKunkle stated is usually a sign of syntax typo.
    Last edited by pkstormy; 04-02-08 at 18:35.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

Posting Permissions

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