Solved

Too Few Parameters. Expected 1

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

856 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