Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Too few parameters Error 3061 in SQL

Status
Not open for further replies.

lizray

Programmer
Joined
May 14, 2008
Messages
126
Location
AU
I have a project for a local Church and am constructing a recordset from an SQL statemant, but when I add the Where and Order by clauses, I get the message "Too few parameters, Expected 3" can anybody please help??. Here is the SQL:
strSQL = "SELECT ChurchAndPriest.Church, ChurchAndPriest.PlaceOfBaptism, Baptisms.BookNum, Baptisms.EntryNum, Baptisms.FamilyName, Baptisms.GivenNames,"
strSQL = strSQL & " Baptisms.DateOfBirth, Baptisms.DateOfBaptism, Baptisms.Notes, Baptisms.BookNum*4000+Baptisms.EntryNum AS BapNumber FROM ChurchAndPriest, Baptisms"
strSQL = strSQL & " WHERE BapNumber Between [FirstEntry] And [LastEntry]"
strSQL = strSQL & " ORDER BY BapNumber;"
FirstEntry and LastEntry are Textboxes.
 
G'day fella,

This line is wrong:
strSQL = strSQL & " WHERE BapNumber Between [FirstEntry] And [LastEntry]"

Should be
strSQL = strSQL & " WHERE BapNumber Between #" & [FirstEntry] & "# And #" & [LastEntry] & "#"

OR

strSQL = strSQL & " WHERE BapNumber Between " & [FirstEntry] & " And " & [LastEntry]

Depending on data type - use # if dates

That will take care of two missing params

To isolate problems like these make the query and then add the parameters manually until you identify the drama.

Sorry for being so vague, it's my bed time now, good luck
 
Thankyou JBinQLD. That solves 2 of the errors, the only problem now seems to be in using BapNumber in either the Where or Order by statements....Any Ideas
 
It looks like you are also missing a join in your FROM clause. I'm not sure if this is intentional but it could cause issues with duplicate records.

Duane
Hook'D on Access
MS Access MVP
 
Is BapNumber really a field of ChurchAndPriest or Baptisms?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
BapNumber is a new field generated from 2 fields from the "Baptisms" table using the AS statement
 
yes that works (with the & " around firstentry etc), but is it not possible to use the generated "BapNumber" field in the where and order by clauses ?
 
Yes, thank you it is now all working. I was just trying to add to my understanding of SQL
 
There are a few places in Access SQL where you can use a field alias in other clauses but, unfortunately, this isn't one of them.

Access evaluates SQL statements in approximately this order
- FROM
- WHERE
- GROUP BY
- HAVING
- ORDER BY
- SELECT

When evaluating the WHERE clause, the field alias defined in the SELECT is not yet known so you must reuse the calculation of the field rather than its name.
 
Thank you Golom. I now understand the situation.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top