?
Solved

openrecordset queryname -- too few parameters

Posted on 2011-03-25
2
Medium Priority
?
513 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 58

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 1600 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
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 …
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Suggested Courses
Course of the Month10 days, 16 hours left to enroll

770 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