Too few parameters error in db.OpenRecordset

R

Reg

I am getting this error:
Runtime Error 3061
Too few parameters. Expected 1

at the line:
Set rstSector = db.OpenRecordset(strSQL, dbOpenDynaset)

When I run this code :

thisSector = lstSectors.Column(1)
Dim db As Database, rstSector As Recordset, strSQL As String

strSQL = "SELECT Reps.Email
FROM (Reps INNER JOIN Companies
ON Reps.CompanyID = Companies.CompanyID)
INNER JOIN Sector ON Companies.SectorID = Sector.SectorID
WHERE (Sector.SectorName)=thisSector"

Set db = CurrentDb()
Set rstSector = db.OpenRecordset(strSQL, dbOpenDynaset)

I would be grateful if someone could tell me where I am going wrong.
Thanks
Reg
 
D

Douglas J. Steele

Try changing your code to:

Dim db As Database, rstSector As DAO.Recordset, strSQL As String

I'm guessing that you have a reference to both ADO and DAO, and that the ADO
reference is higher in the list. When that's the case, simply using As
Recordset will result in an ADO recordset, whereas you need a DAO recordset.
 
G

Guest

Reg:

Concatenate the value of the thisSector variable into the string expression.
If it’s a number:

WHERE (Sector.SectorName)=" & thisSector

Or if thisSector is text:

WHERE (Sector.SectorName)=""" & thisSector & """"

Ken Sheridan
Stafford, England
 
R

Reg

Thanks for the suggestions everyone.
This last solution fixed it for me.
Thanks a lot Ken!

Reg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top