Solved

DAO Recordset query returns parameter error

Posted on 2009-07-10
4
297 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
ID: 24827763
Perhaps this:

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

Author Comment

by:databasefun
ID: 24828395
Unfortunately it still yields the same error
0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
ID: 24828487
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
ID: 31602292
That did it!  Thanks - this was really getting frustrating.
What is the logic behind having to use this method?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

910 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

19 Experts available now in Live!

Get 1:1 Help Now