473,545 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

too few parameters on openrecordset

Hi,

When I do the following in vba:

Set rst = db.OpenRecordse t(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 34214
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.OpenRecordse t(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*********@Se eSig.Invalid> wrote in message
news:3f******** **************@ freenews.iinet. net.au...
"Not Me" <su**@sumwhere. fake> wrote in message
news:bp******** **@ucsnew1.ncl. ac.uk...
When I do the following in vba:
Set rst = db.OpenRecordse t(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
9471
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
1813
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 as DAO objects, and the reference to dao 3.6 is present and working. The code breaks at the last statement (below) with an 'invalid arguament'...
3
47307
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 itself, it works fine. It asks me for the parameter and then it shows the records . What I want is to be able to pass the parameter to it in VBA I am...
4
3435
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
1578
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. Now, I need to read the results of this query in an event procedure, but I consistently get a run-time error (3061): Too few parameters. Expected...
5
5744
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 parameters. The information flow is: 2 parameters -> Prices -> AccountBalances -> {my query} Ideally, I would be able to perform the...
1
22287
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, I've stripped away everything that doesn't cause the error to make my question a little simpler. Here's the problem in its simplest form inside a...
9
2760
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 from searching on the internet and books but the problem is when i run the command button "Export" it just only open the Blank Spreadsheet, no ...
3
3825
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 concatenate the contents of all the records for one field-, and populate the resulting into textbox of a form Private Sub Form_Load() Dim db As...
0
7415
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7675
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7440
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5344
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4963
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3470
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3451
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1902
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1030
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.