Solved

Too Few Parameters. Expected 1

Posted on 2013-12-30
4
733 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
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…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

760 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now