Solved

DAO Recordset query returns parameter error

Posted on 2009-07-10
4
296 Views
Last Modified: 2013-11-27
I have condensed the problem to the the tiny query shown in Code.  When I run the VBA code below on processing the Set rst statement I get a runtime error 3061 : Too few parameters. Expected 1. There is a temporary variable (CurLeadID)  that is setup in a macro that defines it using the settempvars command.  Ultimately it will be set in the code below as well and I have tried doing that directly and using various forms of "" and "' '" to no avail.

If I run the query from Access it runs fine.  If I use the VBA code :

DoCmd.OpenQuery ("Query1",acViewNormal,acReadOnly)

it will run fine as well. But when I try to obtain a recordset from it it fails.  If instead of using the [TempVars]!{CurLeadID] I use a number it works fine. I have used the debugger to make sure the variable is set up correctly before the Set rst statement and it looks fine.
Dim DB As DAO.Database

Dim rst DAO.Recordset
 

Set DB = CurrentDb

Set rst = CurrentDb.OpenRecordset("Query1")
 

Query1  SQL Statement is :
 

SELECT Leads.ID

FROM Leads

WHERE Leads.ID=[TempVars]![CurLeadID];

Open in new window

0
Comment
Question by:databasefun
  • 2
4 Comments
 
LVL 84
Comment Utility
Perhaps this:

SELECT Leads.ID
FROM Leads
WHERE Leads.ID=Eval([TempVars]![CurLeadID]);
0
 

Author Comment

by:databasefun
Comment Utility
Unfortunately it still yields the same error
0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
Comment Utility
create a function in a regular module

function getLeadID() as long
     getLeadID= Nz(TempVars![CurLeadID], 0)
end function

now change the sql of your query1

SELECT Leads.ID
FROM Leads
WHERE Leads.ID=getLeadID()

0
 

Author Closing Comment

by:databasefun
Comment Utility
That did it!  Thanks - this was really getting frustrating.
What is the logic behind having to use this method?
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

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
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…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

772 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

11 Experts available now in Live!

Get 1:1 Help Now