A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Too few parameters error in db.OpenRecordset



 
 
Thread Tools Display Modes
  #1  
Old March 2nd, 2006, 12:00 AM posted to microsoft.public.access.formscoding,microsoft.public.access.gettingstarted
external usenet poster
 
Posts: n/a
Default Too few parameters error in db.OpenRecordset

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


  #2  
Old March 2nd, 2006, 12:05 AM posted to microsoft.public.access.formscoding,microsoft.public.access.gettingstarted
external usenet poster
 
Posts: n/a
Default Too few parameters error in db.OpenRecordset

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.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"Reg" wrote in message
...
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



  #3  
Old March 2nd, 2006, 12:06 AM posted to microsoft.public.access.formscoding,microsoft.public.access.gettingstarted
external usenet poster
 
Posts: n/a
Default Too few parameters error in db.OpenRecordset

Try Sector.SectorName='thisSector'

HTH;

Amy

"Reg" wrote in message
...
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



  #4  
Old March 2nd, 2006, 12:30 AM posted to microsoft.public.access.formscoding,microsoft.public.access.gettingstarted
external usenet poster
 
Posts: n/a
Default Too few parameters error in db.OpenRecordset

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

"Reg" wrote:

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



  #5  
Old March 2nd, 2006, 03:13 AM posted to microsoft.public.access.formscoding,microsoft.public.access.gettingstarted
external usenet poster
 
Posts: n/a
Default Too few parameters error in db.OpenRecordset

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

Reg


"Ken Sheridan" wrote in message
...
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

"Reg" wrote:

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





 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Parameters removed - still get prompted for them Scott F via AccessMonster.com Running & Setting Up Queries 3 January 21st, 2006 03:15 AM
Parameter Query problem Bama_Belle Running & Setting Up Queries 9 June 21st, 2005 06:53 PM
Input Parameters Fail To Reach SP MikeC Setting Up & Running Reports 3 April 11th, 2005 02:25 AM
Executing Update Query With Parameters As ADO Command Barry Jon Running & Setting Up Queries 1 February 16th, 2005 09:09 PM


All times are GMT +1. The time now is 05:50 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.