473,399 Members | 2,159 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,399 software developers and data experts.

error -2147217904 - how to fix :o( ?

using ADODB recordset. trying to use the .open method
SQL uses data from a form [Forms]![Form1]![txtQuantity]
If I replace directly with a number then no problem.
As is, I get error -2147217904 which I gather is likely to be something
to do with quotation marks. Pleeeease help, what was supposed to be a
very simple mock up is taking for ever
:o(

Dec 22 '05 #1
21 8046
Show us All the code.
or
Wait for the guessers, mind-readers, seers, wizards etc.

Dec 22 '05 #2
Dim rs As New ADODB.Recordset
rs.Open "SELECT LowerQuantity FROM tblQuantityPriceBands WHERE
LowerQuantity <= [Forms]![Form1]![txtQuantity]",
CurrentProject.Connection, adOpenKeyset, adLockOptimistic, adCmdText

Dec 22 '05 #3
Suggest

s.Open "SELECT LowerQuantity FROM tblQuantityPriceBands WHERE
LowerQuantity <= " & [Forms]![Form1]![txtQuantity]

Dec 22 '05 #4
my own fault for oversimplfying - sorry
actually there are a number of 'layered' stored procedures which take
data from the form.
so the true code would be something like
rs.Open "qryPrices", CurrentProject.Connection, adOpenKeyset,
adLockOptimistic, adCmdStoredProc

where the sql in the query looks like that posted earlier.
same error message though :(

Dec 22 '05 #5
or******@hotmail.com wrote:
my own fault for oversimplfying - sorry
actually there are a number of 'layered' stored procedures which take
data from the form.
so the true code would be something like
rs.Open "qryPrices", CurrentProject.Connection, adOpenKeyset,
adLockOptimistic, adCmdStoredProc

where the sql in the query looks like that posted earlier.
same error message though :(


Stored Procedures?????????

This is MS-SQL??????????

I must have missed that.

MS-SQL will have zero knowledge of your forms.

You may be more successful using Sprocs and Command Objects with
Parameters, or dynamic SQL strings as you showed in your first post.

--
Lyle Fairfield
Dec 22 '05 #6
I only call them stored procedures because that's what the enumeration
adCmdStoredProc says. All they are, are normail standard queries in
Access. Queries which work perfectly but that I can't use to populate
a recordset in VBA.
Maybe my question is how can I use a access query to populate a
recordset when the query takes data from a form.
I reeeeeeeeeeeallly don't want to use SQL strings directly because they
would be very complex and difficult to maintain.

Thanks for terse help so far :o)

Dec 22 '05 #7
Good luck.

Dec 22 '05 #8
or******@hotmail.com wrote in message
<11**********************@g44g2000cwa.googlegroups .com> :
I only call them stored procedures because that's what the enumeration
adCmdStoredProc says. All they are, are normail standard queries in
Access. Queries which work perfectly but that I can't use to populate
a recordset in VBA.
Maybe my question is how can I use a access query to populate a
recordset when the query takes data from a form.
I reeeeeeeeeeeallly don't want to use SQL strings directly because they
would be very complex and difficult to maintain.

Thanks for terse help so far :o)


Let's say you have a query1:

select field1, field2, field3
from mytable
where field4 = forms!form1!test

I would probably start with "declaring" the parameter

parameters forms!form1!test long;
select <rest of query>

Then try something like this air code (maybee you need some
[brackets] here and there)

dim cmd as adodb.command
dim prm as adodb.parameter
Dim rs As ADODB.Recordset

set cmd = new adodb.command
with cmd
set .activeconnection = currentproject.connection
.commandtext = "query1"
.commandtype = adcmdstoredproc
set prm = createparameter("forms!form1!test", adInteger,
adparaminput)
.parameters.append prm
.prm.value = Forms!Form1!txtQuantity
' to get readonly forwardonly
set rs = .execute
end with
' to get updateable
set rs = new adodb.recordset
rs.Open cmd, , adOpenKeyset, adLockOptimistic

--
Roy-Vidar

Dec 22 '05 #9
oooooooooooooh this is just too blinking complicated - I just want to
use the same query in my code that works perfectly when it is bound to
a control.
that's all - I'm not asking for the world
if I make the queries parameterized then I can't use them behind the
form too.
the code snippet above isn't going to make life much easier because
there are 4 or 5 queries before which may or may not require a
parameter.
is this an ADODB issue that I can solve by using DAO?

Dec 22 '05 #10
or******@hotmail.com wrote:
is this an ADODB issue that I can solve by using DAO?


You could try and let us know I hope.

--
Lyle Fairfield
Dec 22 '05 #11
using DAO doesn't fix it - strange - I would have thought I would have
come across this years ago then............

Dec 22 '05 #12
Maybe dynamic SQL strings? Maybe Command Objects and Parameters? Many
of us use these as a matter of course in our work. Can they be SO
difficult?

Dec 22 '05 #13
looks like I'll have to. But i am a bit annoyed that what I want to do
(which seems very trivial) is not possible.
The sql is going to be lengthy and hard to maintain and I'm not happy
about that :(
Why oh why wouldn't this sort of thing be catered for .....like I
said...annoying

Dec 22 '05 #14
Perhaps it is possible but we haven't found the way.
As I never do it, it's unlikely that I ever will.
One of the ways I use to deal with lengthy and hard to maintain SQL is
to use the Command Object and its parameters.
I also use Const SQL strings and the Replace function to make this a
little easier (for me).

Dec 22 '05 #15
or******@hotmail.com wrote in
news:11*********************@g44g2000cwa.googlegro ups.com:
looks like I'll have to. But i am a bit annoyed that what I want
to do (which seems very trivial) is not possible.
The sql is going to be lengthy and hard to maintain and I'm not
happy about that :(
Why oh why wouldn't this sort of thing be catered for .....like I
said...annoying


Write the SQL on the fly. That is, don't include a WHERE clause in
your stored query, and add the WHERE clause based on the value from
the form when you need it.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Dec 22 '05 #16
sorry david, maybe I am being a bit dim but I don't quite understand.
If the queries don't have the where clauses then the won't work in
other circumstances.
Either way - isn't that similar to "dynamic" SQL ( a phrase from above)
which seems to mean a string of SQL language with a variable embeded in
it - in this case the value of a control on a form

Dec 22 '05 #17
Here's how you would do it in DAO, but I'm not sure what changes need
to be made ito utlize ADO...sounds like your query needs a parameter
that it isn't getting. To pass a parameter to a query, you first set
the QueryDef object, then set the parameter (note that it is entirely
enclosed in brackets, unlike the normal way you reference a form
field), and THEN set it to a recordset object.
*aircode*
Dim dbs as Database
Dim qdf as QueryDef
Dim rs as Recordset

Set dbs = CurrentDb()
Set qdf = dbs.QueryDefs("qryPrices")
qdf![Forms!Form1!txtQuantity] = [Forms]![Form1]![txtQuantity]
Set rs = qdf.OpenRecordset(INSERT YOUR RS OPTIONS HERE)
Do the rest of your stuff here

HTH,
Jana

Dec 22 '05 #18
rkc
or******@hotmail.com wrote:
oooooooooooooh this is just too blinking complicated - I just want to
use the same query in my code that works perfectly when it is bound to
a control.
that's all - I'm not asking for the world
if I make the queries parameterized then I can't use them behind the
form too.


If you are referencing a form and control in your query then the query
is parameterized. The parameter is:

[Forms]![Form1]![txtQuantity]

If you just want to use the query in code when the form it references is
open then use DAO and open the recordset using the name of the query.

If you want to use the query when the form isn't open then you will have
to supply a value for the parameter. You do that in DAO using the
parameters collection of the querydef object. You do that in ADO by
creating and appending a parameter object to the parameters collection
of an ADODB.Command object. Either way takes writing a little code. More
using ADO then DAO, but nothing to whine about.
Dec 22 '05 #19
or******@hotmail.com wrote in
news:11*********************@f14g2000cwb.googlegro ups.com:
sorry david, maybe I am being a bit dim but I don't quite
understand. If the queries don't have the where clauses then the
won't work in other circumstances.
If the saved queries don't have WHERE clauses, yes, the saved
queries return all the records.
Either way - isn't that similar to "dynamic" SQL ( a phrase from
above) which seems to mean a string of SQL language with a
variable embeded in it - in this case the value of a control on a
form


Well, I don't know. When I say on-the-fly SQL, I mean that somewhere
in code, you define the WHERE clause and assign the SQL as a
recordsource for your report or form. This is very different from
embedding parameters or references to form controls in the SQL,
which is something I avoid doing (except in the one or two
situations where it is pretty much required; those are very
uncommonly needed, in my experience).

The point is that if you need to open a filtered report or form, you
use the base saved query and add a WHERE clause. DoCmd.OpenForms and
DoCmd.OpenReport can both take a WHERE clause argument that will
filter the result, so you don't need to embed anything in your saved
query.

And mostly, I don't use saved queries that much as plain old
recordsources. I only use them when I need nested queries to an
extent that is greater than what is allowed with subqueries of the
"[]. As Alias" form.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Dec 23 '05 #20
rkc <rk*@rochester.yabba.dabba.do.rr.bomb> wrote in
news:DS*******************@twister.nyroc.rr.com:
If you are referencing a form and control in your query then the
query is parameterized. The parameter is:

[Forms]![Form1]![txtQuantity]

If you just want to use the query in code when the form it
references is open then use DAO and open the recordset using the
name of the query.


Is it not the case that DAO can't resolve control references?

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Dec 23 '05 #21
rkc
David W. Fenton wrote:
rkc <rk*@rochester.yabba.dabba.do.rr.bomb> wrote in
news:DS*******************@twister.nyroc.rr.com:

If you are referencing a form and control in your query then the
query is parameterized. The parameter is:

[Forms]![Form1]![txtQuantity]

If you just want to use the query in code when the form it
references is open then use DAO and open the recordset using the
name of the query.

Is it not the case that DAO can't resolve control references?


You are correct. The parameter needs to be set using the
parameters collection even if the form is open.

I was confused by being able to open the saved query in the query
window without supplying a parameter if the form is open.


Dec 23 '05 #22

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

Similar topics

11
by: nkechifesie | last post by:
When I run this code to update my database Set AdVehDecp = New ADODB.Connection Set RsVehDecp = New ADODB.Recordset AdVehDecp.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=...
1
by: Akinyemi | last post by:
I created a Database which I named "Address". I went through the Control Panel and created a DSN to enable me connect to the Database through ODBC. I then created a Form with the same fields as...
4
by: normleev | last post by:
Access 2003 version I get the above error when I execute the following code and have been unable to debug. Suggestions? Dim custrst As New ADODB.Recordset, strSQLStmt As String, strWhere...
2
by: katrinkerber | last post by:
Hello, I need help to solve a runtime error that keeps reocurring every time I try to convert an Excel file into an Acess File. I have looked through many forums trying to find help, but I have...
2
by: VaTravo | last post by:
I am using access database as my back-end and Visual basics 6.0 as my front-end.my application must generate dynamic reports and i have tried using the article by Farhana but the during execution...
0
by: =?Utf-8?B?TWljaGVsbGU=?= | last post by:
What is wrong with this code?!! I am getting a run-time error (-2147217904 80040e10) error "No value given for one or more required parameters. If I substitute the DeptID "5" in the query it works...
20
pentahari
by: pentahari | last post by:
I get the following error: run-time error '-2147217904 (80040e10)' Method 'open' of object '_Recordset' field How to solve the problem? Please Help me. I am waiting for your response. Dim CONN...
0
by: vasavasnehal | last post by:
Hi all..! Give me information and solution for this error Runtime error: 2147217904(80040e10) No value given for one ot more equired parameters. My project code: Private Sub Form_Load()
1
by: zedd | last post by:
Hi, I orignaly posted this with the error above, however I am still trying to solve it on my own, and found that some of my syntax in the query was not correct and I corrected it. But i am still...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
0
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...
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,...

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.