Solved

Too Few Parameters. Expected 1

Posted on 2013-12-30
4
814 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 40

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 85
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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.

717 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