run time error 3061 - too few parameters. expected 2
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.
thanx in advance guyz
Re: run time error 3061 - too few parameters. expected 2
Welcome to VBForums :wave:
Thread moved from the 'CodeBank VB6' forum (which is for you to post working code examples, not questions) to the 'Database Development' forum... the 'VB6 and earlier' forum would be the place if it wasn't covered by a more specific forum
Your syntax is basically good, so there are several potential causes for the error, including:
* The simplest is that you may have typed one of the field names wrong.
* One of the field names might not be safe. For more information (including lists of Reserved words), see the article What names should I NOT use for tables/fields/views/stored procedures/...? from our Database Development FAQs/Tutorials (at the top of this forum)
* The text of one of the combo's might contain the ' character, or some other escape sequence.
Re: run time error 3061 - too few parameters. expected 2
Use a string variable to compose/resolve your query, and then Debug.Print it to see what it looks like.
Code:
Dim sSQL As String
sSQL = "Select * from Table_Name WHERE Field1 like '" & combo1.Text & "' AND Field2 like '" & combo2.Text & "' AND Field3 like '" & combo3.Text & "'"
Debug.Print sSQL
dt.RecordSource = sSQL
dt.Refresh
9 times out of 10 when I do that, I can study the query, and can work out what is going wrong.
To study your query (after running the program) Press Ctrl G to show the immediate window.
Copy what is in there into Notepad, and study it.
If you don't see the problem then, you can paste the result here for us to look at.