Solved

openrecordset queryname -- too few parameters

Posted on 2011-03-25
2
482 Views
Last Modified: 2012-06-22
Hi,
I'm using MS Access 2000.

I'm getting a too few parameters error on this openrecordset line:
    Set db = CurrentDb()
    Set rs = db.OpenRecordset("Q_tags_aisle4", dbOpenDynaset)

Q_tags_aisle4 looks like this:
SELECT DISTINCT Q_tags_aisle1.BRAND, Q_tags_aisle1.Aisle
FROM Q_tags_aisle1;

Q_tags_aisle1 looks like this:
SELECT Left([tbl_line_setup].[RESRV],4) AS Aisle, Left([tbl_line_setup].[BCKUP],4) & " " & Right([tbl_line_setup].[BCKUP],5) AS BCKUP, tbl_line_setup.BRAND, tbl_line_setup.PROGRAM
FROM tbl_line_setup
WHERE (((Left([tbl_line_setup].[RESRV],4))<>"") AND ((tbl_line_setup.PROGRAM)=[Forms]![Main].[txtProgramPass]))
ORDER BY Left([tbl_line_setup].[RESRV],4);

I put a textbox on the form that I set equal to the Program value that the query uses in its criteria.
txtProgramPass.Value = sProgram

The sProgram variable is passing the value correctly and I see it display in the textbox when I step through.

The query runs fine if I just run it myself, but the openrecordset is not working.  If I hardcode the criteria into the query then the openrecordset does work, but I obviously can't leave it like that.

What can I try here?

Thanks,
Dave


0
Comment
Question by:coperations07
2 Comments
 
LVL 57

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 400 total points
ID: 35215450
When you open a query in code, Access will not resolve reference for you, you must do it.  Since these are just form references, you can do it like this:

Dim db As Database
Dim qdef As QueryDef
Dim prm as Parameter
Dim rs As Recordset


Set db = CurrentDb()
Set qdef = db.QueryDefs("Q_tags_aisle4")
For Each prm in qdf.Parameters
prm.Value = Eval(prm.Name)
Next prm
Set rs = qdef.OpenRecordset()  

JimD.
0
 

Author Closing Comment

by:coperations07
ID: 35215658
Thank you sir! One day I will know everything...I hope. :)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

816 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