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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query returns zero recordsets after being opening as a recordset 2

Status
Not open for further replies.

TimPen

Technical User
Mar 28, 2011
41
ZA
I have a parameter query based on fields in a form.

If I populate the form and manually open the query, records are correctly returned.
If I use the query in a recordset (the form is open and correctly populated) the vba opening the recordset returns a run-time error 3061 - Too few parameters. Expected 2
If don't stop the code, and manually open the query, no records are returned.

Why is this?
 
How are ya TimPen . . .

Typically this error rises when a field is mispelled or there's a datatype problem. Could also be due to improper concatenation of the SQL.

In any case post the SQL.

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
SELECT tblCustomer.EMail
FROM tblCustomer
WHERE (((tblCustomer.EMail) Is Not Null) AND ((tblCustomer.DefaultRepId) Like [Forms]![frmGenerateEMailList]![cboRepresentative]) AND ((tblCustomer.CustomerStatusId) Like [Forms]![frmGenerateEMailList]![cboCustomerStatus]));
 
A starting point to open a recordset from a parametized query:
Code:
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim prm As DAO.Parameter
Dim rst As DAO.Recordset

Set db = CurrentDb
Set qdf = db.QueryDefs("NameOfQuery")
For Each prm In qdf.Parameters
  prm.Value = Eval(prm.Name)
Next prm
Set rst = qdf.OpenRecordset

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Another thing that has caught me before now has been if the field holding your parameter data on the form still has the focus when you run the query - at this point the field is not recognised as updated so the query treats it as null....

Nigel
Didn't someone say work is supposed to be fun? They didn't have computers then I guess....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top