473,406 Members | 2,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

too few parameters on openrecordset

Hi,

When I do the following in vba:

Set rst = db.OpenRecordset(sql)

I get the too few parameters (expected 3) error. I've seen quite a lot of
this on google but all seem to be caused by incorrect sql, but mine works
fine when I print it out into a query. From what I can tell the parameters
are optional so I don't really understand the problem.

I have dim-ed the recordset as dao.recordset.

Cheers,
Chris
Nov 12 '05 #1
2 34199
The error message means that JET is unable to resolve some of the names in
the query.

If the query contains things to Forms!SomeForm!SomeControl, it will work in
the query window, but not in code. The solution is to concatenate the value
of the controls into the sql string. That is, instead of:
sql = "SELECT ... WHERE SomeField = Forms!SomeForm!SomeControl;"
use:
sql = "SELECT ... WHERE SomeField = " & Forms!SomeForm!SomeControl & ";"

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Not Me" <su**@sumwhere.fake> wrote in message
news:bp**********@ucsnew1.ncl.ac.uk...
Hi,

When I do the following in vba:

Set rst = db.OpenRecordset(sql)

I get the too few parameters (expected 3) error. I've seen quite a lot of
this on google but all seem to be caused by incorrect sql, but mine works
fine when I print it out into a query. From what I can tell the parameters are optional so I don't really understand the problem.

I have dim-ed the recordset as dao.recordset.

Nov 12 '05 #2
"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:3f**********************@freenews.iinet.net.a u...
"Not Me" <su**@sumwhere.fake> wrote in message
news:bp**********@ucsnew1.ncl.ac.uk...
When I do the following in vba:
Set rst = db.OpenRecordset(sql)
I get the too few parameters (expected 3) error. I've seen quite a lot of this on google but all seem to be caused by incorrect sql, but mine works fine when I print it out into a query. From what I can tell the parameters
are optional so I don't really understand the problem.

The error message means that JET is unable to resolve some of the names in
the query.

If the query contains things to Forms!SomeForm!SomeControl, it will work in the query window, but not in code. The solution is to concatenate the value of the controls into the sql string. That is, instead of:
sql = "SELECT ... WHERE SomeField = Forms!SomeForm!SomeControl;"
use:
sql = "SELECT ... WHERE SomeField = " & Forms!SomeForm!SomeControl & ";"


Nice one, stupid mistake to make I guess.

Cheers,
Chris
Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Dee | last post by:
Running an AfterUpdate event procedure, I get the following error: "Too few parameters. Expected 1." My code is as follows: Private Sub DealerID_AfterUpdate() Dim db As DAO.Database
1
by: Gerry Abbott | last post by:
Hi all I'm converting a db from Acc97 to 2000. Everything works, except assigning of a qdf object containing parameters, to a recordset. The db, recordset, and qrydef objects are all referenced...
3
by: Nicolae Fieraru | last post by:
Hi All, I have a table, tblCustomers, with fields SalutationID and Firstname. I made a query, qrySelect = "Select FirstName from tblCustomers Where SalutationID = " If I run this query by...
4
by: Weaver | last post by:
Supposing I wanted to do something like this: Set rsB = db.OpenRecordset("qryStuff") only qryStuff required parameters? How do I pass the parameter values to the query? Thanks.
0
by: Greg Pyle | last post by:
I have created a parameter query (qryAuthors) that reads three parameters from three different fields on a subform (Subform1). Each time the form record changes, the query updates automatically. ...
5
by: billelev | last post by:
Hi There, I am trying to execute a query using openRecordset on a query called 'AccountValues'. The 'AccountValues' query relies on another query, 'Prices', which in turn relies on a form for two...
1
by: Richard Hollenbeck | last post by:
I wonder what I'm missing? I really feel like a retard because I've been screwing with some code for a very long time. I just must be missing something very simple. In the following example,...
9
by: QCLee | last post by:
Sir can you help me to transfer my Access Query to MS excel? i have a command button on the form to export the parameter query named "HVACWindwardQuery" to excel spreadsheet and i got the codes...
3
by: Kassimu | last post by:
Hi there, I have a table with thousands of record entries, usually the user searches this table through SearchForm resulting into some recordset. What I need to do on this recordset is to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.