9 Replies - 1305 Views - Last Post: 31 January 2013 - 11:11 PM Rate Topic: -----

#1 valerov  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 26-January 13

run time error 3061 - too few parameters. expected 2

Posted 26 January 2013 - 03:52 PM

hello everyone. im getting the error: "run time error 3061 - too few parameters. expected 2" when using a select query. i have the following code:

 dt.recordsource="Select * from Table_Name WHERE Field1 like '" & combo1.text & "' AND Field2 like '" & combo2.text & "' AND Field3 like '" & combo3.text & "'"
dt.refresh 


if i use the following, it works great:

 dt.recordsource="Select * from Table_Name WHERE Field1 like '" & combo1.text & "'"
dt.refresh 


so i guess i use wrong syntax after 'WHERE' parameter.

thanks in advance guyz

Is This A Good Question/Topic? 0
  • +

Replies To: run time error 3061 - too few parameters. expected 2

#2 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3488
  • View blog
  • Posts: 11,902
  • Joined: 12-December 12

Re: run time error 3061 - too few parameters. expected 2

Posted 26 January 2013 - 04:11 PM

It might be because you are using LIKE but you haven't supplied any wildcards. They may be * and ?, or % and _, depending on your database system. Alternatively, use equals = if you are not using wildcards.

This post has been edited by andrewsw: 26 January 2013 - 04:12 PM

Was This Post Helpful? 0
  • +
  • -

#3 valerov  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 26-January 13

Re: run time error 3061 - too few parameters. expected 2

Posted 27 January 2013 - 12:49 AM

i replaced "like" with "=" but i keep getting the same error. I think its because i use the WHERE statement with wrong syntax. if i use "WHERE field like combobox1" and nothing else its running good. if i use "WHERE field like combobox1 AND field2 like combobox2 AND field3 like combobox 3 then i get the error
Was This Post Helpful? 0
  • +
  • -

#4 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 300
  • View blog
  • Posts: 1,776
  • Joined: 26-March 09

Re: run time error 3061 - too few parameters. expected 2

Posted 27 January 2013 - 02:37 AM

Have you tried assigning your query to a variable and checking what it looks like in the immediate window once it's populated?

Are there any field type mismatches, looking at your query all fields appear to be strings, is that correct? Not sure whether this would cause that error or not.

An idea of the schema and data going in would be useful.

I'm no DB/SQL expert, so these are just observations.
Was This Post Helpful? 0
  • +
  • -

#5 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3488
  • View blog
  • Posts: 11,902
  • Joined: 12-December 12

Re: run time error 3061 - too few parameters. expected 2

Posted 27 January 2013 - 04:28 AM

Follow the advice given by maj3091. You could also try

dt.recordsource="Select * from Table_Name WHERE Field1 = '" & combo1.text & "'"
dt.refresh 

and repeat this for Field2 and Field3, separately. Then you might discover which of the three fields is the issue.

But store the SQL statement in a variable and post it here.
Was This Post Helpful? 0
  • +
  • -

#6 guyfromri  Icon User is offline

  • D.I.C Addict

Reputation: 46
  • View blog
  • Posts: 817
  • Joined: 16-September 09

Re: run time error 3061 - too few parameters. expected 2

Posted 28 January 2013 - 12:19 PM

In my experience this error usually relates to a table name or a field name spelled wrong. If you look at it too long you'll never see it. Hand type each field name, combo name and table name slowly to see if it works. :)
Was This Post Helpful? 0
  • +
  • -

#7 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3488
  • View blog
  • Posts: 11,902
  • Joined: 12-December 12

Re: run time error 3061 - too few parameters. expected 2

Posted 28 January 2013 - 12:27 PM

I should whisper this but "Too few parameters" can also be an indicator of a corrupted database :helpsmilie:
Was This Post Helpful? 0
  • +
  • -

#8 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 180
  • View blog
  • Posts: 1,606
  • Joined: 17-April 07

Re: run time error 3061 - too few parameters. expected 2

Posted 28 January 2013 - 09:09 PM

to my consideration the combo box text has some single quote character that's why this error will popup
seems the combo box text has
some thing like this
Shakespeare's Romeo and Juliet

so the solution is you need to use the parameter search this will solve your problem
Was This Post Helpful? 0
  • +
  • -

#9 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: run time error 3061 - too few parameters. expected 2

Posted 31 January 2013 - 11:06 PM

View Postandrewsw, on 26 January 2013 - 05:11 PM, said:

It might be because you are using LIKE but you haven't supplied any wildcards. They may be * and ?, or % and _, depending on your database system. Alternatively, use equals = if you are not using wildcards.

Like and = are equivalent if there are no wildcards. Like doesn't error out if there aren't any.

This post has been edited by BobRodes: 31 January 2013 - 11:06 PM

Was This Post Helpful? 0
  • +
  • -

#10 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: run time error 3061 - too few parameters. expected 2

Posted 31 January 2013 - 11:11 PM

View Postthava, on 28 January 2013 - 10:09 PM, said:

to my consideration the combo box text has some single quote character that's why this error will popup
seems the combo box text has
some thing like this
Shakespeare's Romeo and Juliet

so the solution is you need to use the parameter search this will solve your problem

I was thinking the same thing. If so, you can do this for each of your combo boxes:
Replace(comboX.Text, "'", "''")
If you want a literal ', then in SQL you double it, so: ''. For example: O''Malley.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1