Solved

Too Few Parameters. Expected 1

Posted on 2013-12-30
4
806 Views
Last Modified: 2013-12-30
I am attempting to run the following code...

Dim EESQL As String
Dim db As Database
Dim rs As DAO.Recordset
EESQL = "SELECT Max(os_claims.EmployeeID) AS MaxOfEmployeeID " & _
	"FROM os_claims " & _
	"WHERE (((os_claims.DateClosed) Is Null) AND ((os_claims.ArchivedRecord)=False) AND ((os_claims.EmployeeID)=[forms]![frmEmployees]![id]));"
Set db = CurrentDb
Set rs = db.OpenRecordset(EESQL)
Me.selectedEEFound.Value = rs.Fields("MaxOfEmployeeID").Value
Set rs = Nothing
Set db = Nothing

Open in new window


...but when I do, I received a "Too Few Parameters. Expected 1" error.  Through debugging, I know there error is occurring at the "Set rs = db.OpenRecordset(EESQL)" line in the code...but I don't know why.

If I paste the sql code into a query, it runs fine without any issues or errors.
0
Comment
Question by:OSI-IT
4 Comments
 
LVL 39

Accepted Solution

by:
als315 earned 250 total points
ID: 39746263
You can't use [forms]![frmEmployees]![id] inside quotes. Try
...AND ((os_claims.EmployeeID)= " & [forms]![frmEmployees]![id] & "));"
if os_claims.EmployeeID is numeric
0
 
LVL 28

Assisted Solution

by:omgang
omgang earned 250 total points
ID: 39746268
You need to explicitly pass Form reference parameters when opening a DAO recordset on a parameter query.  Give this a shot.
OM Gang


Dim EESQL As String
Dim db As Database

Dim qdf As DAO.QueryDef

Dim rs As DAO.Recordset
EESQL = "SELECT Max(os_claims.EmployeeID) AS MaxOfEmployeeID " & _
      "FROM os_claims " & _
      "WHERE (((os_claims.DateClosed) Is Null) AND ((os_claims.ArchivedRecord)=False) AND ((os_claims.EmployeeID)=[forms]![frmEmployees]![id]));"
Set db = CurrentDb

Set qdf = db.CreateQueryDef("", EESQL)
qdf.Parameters("[forms]![frmEmployees]![id]") = [forms]![frmEmployees]![id]

'Set rs = db.OpenRecordset(EESQL)

Set rs = qdf.OpenRecordset

Me.selectedEEFound.Value = rs.Fields("MaxOfEmployeeID").Value
Set rs = Nothing

Set qdf = Nothing

Set db = Nothing
0
 
LVL 84
ID: 39746274
Also be sure that your Table and Field names are spelled correctly. "Too Few Parameters" generally means that your query cannot find a field, and sometimes that's just a typo ....
0
 

Author Closing Comment

by:OSI-IT
ID: 39746284
Thanks for catching my noob error AND providing an alternate way passing form reference parameters
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question