Too few paramaters. Expected 2 in OpenRecordset (1 Viewer)

Timax

Registered User.
Local time
Today, 11:18
Joined
May 14, 2015
Messages
33
Hi, I have done this million times with no problem and this simple statement gives me problem "Too few parameters. Expected 2:. What am I missing here?

Dim sSQL As String
Dim db As Database
Dim rs As Recordset

sSQL = "SELECT EmailsPeopleM.JobID, EmailsPeopleM.CustName, EmailsPeopleM.[First Name], EmailsPeopleM.[Last Name], EmailsQtyUnion.PartNumber, EmailsQtyUnion.Description, EmailsQtyUnion.Rev, EmailsQtyUnion.InitialQty, EmailsQtyUnion.StateName, EmailsQtyUnion.RealQty, EmailsPeopleM.email, EmailsPeopleM.CustID FROM EmailsPeopleM LEFT JOIN EmailsQtyUnion ON EmailsPeopleM.JobID = EmailsQtyUnion.JobID;"

Set db = CurrentDb
Set rs = db.OpenRecordset(sSQL, dbOpenDynaset, dbSeeChanges)

Query works fine by itself... Please guide me here.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 02:18
Joined
May 7, 2009
Messages
19,242
change these two to:

Dim db As DAO.Database
Dim rs As DAO.Recordset
 

Timax

Registered User.
Local time
Today, 11:18
Joined
May 14, 2015
Messages
33
Thank you but same problem. Did not help
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 02:18
Joined
May 7, 2009
Messages
19,242
how about querydef:

with currentdb.createquerydef("", sSQL)
Set rs=.OpenRecordset(dbOpenDynaset)
End With
 
Last edited:

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 13:18
Joined
Feb 28, 2001
Messages
27,182
Are there any real line breaks in the string declaration?
 

Gasman

Enthusiastic Amateur
Local time
Today, 19:18
Joined
Sep 21, 2011
Messages
14,294
Hi, I have done this million times with no problem and this simple statement gives me problem "Too few parameters. Expected 2:. What am I missing here?

Dim sSQL As String
Dim db As Database
Dim rs As Recordset

sSQL = "SELECT EmailsPeopleM.JobID, EmailsPeopleM.CustName, EmailsPeopleM.[First Name], EmailsPeopleM.[Last Name], EmailsQtyUnion.PartNumber, EmailsQtyUnion.Description, EmailsQtyUnion.Rev, EmailsQtyUnion.InitialQty, EmailsQtyUnion.StateName, EmailsQtyUnion.RealQty, EmailsPeopleM.email, EmailsPeopleM.CustID FROM EmailsPeopleM LEFT JOIN EmailsQtyUnion ON EmailsPeopleM.JobID = EmailsQtyUnion.JobID;"

Set db = CurrentDb
Set rs = db.OpenRecordset(sSQL, dbOpenDynaset, dbSeeChanges)

Query works fine by itself... Please guide me here.

What about the query this sql is getting it's data from?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 02:18
Joined
May 7, 2009
Messages
19,242
gasman you are right, it might be qbf.
 

Timax

Registered User.
Local time
Today, 11:18
Joined
May 14, 2015
Messages
33
Same result with QueryDef... Can't believe this. Query gets data from SQL Server originally. It's going thru multiple layers of query including union query but query itself works by itself as I mentioned... What else can it be? Can't believe I stock on this simple statement.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 11:18
Joined
Aug 30, 2003
Messages
36,125
If there are form references in any of the queries, OpenRecordset will not be able to resolve them. Simplest solution is probably to to wrap each in the Eval() function.
 

Timax

Registered User.
Local time
Today, 11:18
Joined
May 14, 2015
Messages
33
Thank you Paul. Yes, there is a form reference inside of precursor query but not in openrecordset statement. Would that still be a problem? Also, I never used this Eval() function. Do I need to use it wrapping form reference?
 

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 04:18
Joined
Jan 20, 2009
Messages
12,852
Yes, there is a form reference inside of precursor query but not in openrecordset statement. Would that still be a problem?

Definitely. OpenRecordset is a Method of the database, not the Application so the SQL is sent directly to the engine without interpreting any references.

Also, I never used this Eval() function. Do I need to use it wrapping form reference?

Eval() is an Application function which can be called from the database. It understands the form reference and returns a value.
 

Timax

Registered User.
Local time
Today, 11:18
Joined
May 14, 2015
Messages
33
Eval() did not help. I wrapped references with Eval() and query works fine but still same error in OpenRecordset... What else can I try?
 

Timax

Registered User.
Local time
Today, 11:18
Joined
May 14, 2015
Messages
33
Form is open. I researched that one first :)
 

Gasman

Enthusiastic Amateur
Local time
Today, 19:18
Joined
Sep 21, 2011
Messages
14,294
Use Tempvars? in the precursor query?
 

Timax

Registered User.
Local time
Today, 11:18
Joined
May 14, 2015
Messages
33
Dim db As ADO.Database
Dim rs As ADO.Recordset
Set db = CurrentDb
sql = SQLStatement
Set rs = db.OpenRecordset(sql, dbOpenSnapshot)

Anything is wrong here? sql query is no problem when open outside of the function
 

Timax

Registered User.
Local time
Today, 11:18
Joined
May 14, 2015
Messages
33
No, no tempvars in presecur. standard form references.
 

Gasman

Enthusiastic Amateur
Local time
Today, 19:18
Joined
Sep 21, 2011
Messages
14,294
What I was suggesting was to USE Tempvars as the parameters instead of the form references. ?

That way the form does not have to be open.?

That is an approach I have used when I wanted a query to be used from several forms.?
 

Timax

Registered User.
Local time
Today, 11:18
Joined
May 14, 2015
Messages
33
Can't do that. I use form references in queries that are way before this final query I use in openrecordset. Form is open. If I use debug.print and put this into query, everything works.
 

Timax

Registered User.
Local time
Today, 11:18
Joined
May 14, 2015
Messages
33
I resolved this by replacing form references with TempVars and it worked :) Thank you all!!!!!
 

Users who are viewing this thread

Top Bottom