?
Solved

Too Few Parameters. Expected 1

Posted on 2013-12-30
4
Medium Priority
?
818 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 1000 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 1000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Suggested Courses

764 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