473,386 Members | 1,908 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,386 software developers and data experts.

OpenRecordset help - Run time error 3061 (Too few parameters. Expected 1)

I am trying to open a recordset and I am getting an error and I can't
figure out why.

See code below. sqlString2 does not work. sqlString does. Clearly
the problem is with the nested SELECT statement. But when I copy
sqlString2 into a new query it runs just fine. Futhermore, I have
used a nested SELECT statement with the OpenRecordset() method before
and it works just fine. Any ideas?

thanks much,
jon
Here's my code:

sqlString = "SELECT [Confirmation Sent?], [Date Confirmation] " & _
"FROM [Transaction / Billing Information Info];"

'sqlString2 = "SELECT [Confirmation Sent?], [Date Confirmation] " & _
' "FROM [Transaction / Billing Information Info] " & _
' "WHERE (([Transaction ID]) In " & _
' "(SELECT [Transaction ID] FROM [qry confirmation letter] " & _
' "WHERE (([Person ID] = 26000052))));"

Debug.Print (sqlString)

Set dbs = CurrentDb
Set rs = dbs.OpenRecordset(sqlString, dbOpenDynaset)
Nov 13 '05 #1
6 8517
Jonathan LaRosa wrote:
I am trying to open a recordset and I am getting an error and I can't
figure out why.

See code below. sqlString2 does not work. sqlString does. Clearly
the problem is with the nested SELECT statement. But when I copy
sqlString2 into a new query it runs just fine. Futhermore, I have
used a nested SELECT statement with the OpenRecordset() method before
and it works just fine. Any ideas?

thanks much,
jon
Here's my code:

sqlString = "SELECT [Confirmation Sent?], [Date Confirmation] " & _
"FROM [Transaction / Billing Information Info];"

'sqlString2 = "SELECT [Confirmation Sent?], [Date Confirmation] " & _
' "FROM [Transaction / Billing Information Info] " & _
' "WHERE (([Transaction ID]) In " & _
' "(SELECT [Transaction ID] FROM [qry confirmation letter] " & _
' "WHERE (([Person ID] = 26000052))));"

Debug.Print (sqlString)

Set dbs = CurrentDb
Set rs = dbs.OpenRecordset(sqlString, dbOpenDynaset)

Why not create a new temp query, add the table [Transaction / Billing
Information Info] and the query [qry confirmation letter], create a join
line between TXID, and a whereclause for the PersonID. Run it to
verify. Then do a View/SQL, copy to clipboard, and paste the SQL string
in the code, and separate with quotes as above. It will also be faster
than doing a Select ID from ... where .... in ...
Nov 13 '05 #2
The reason I can't take your suggestion and create a new query rather
than use the nested SELECT statement is because that nested SELECT
statment is dynamically generated at runtime. I have removed the
references to the variable that is used there because I thought that
could be causing my problems. Unfortunately that was not the cause of
my problems.

thanks for your help though.

any other ideas?
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #3
"Jonathan LaRosa" <jl*****@alumni.brown.edu> wrote in message
news:e6**************************@posting.google.c om...
I am trying to open a recordset and I am getting an error and I can't
figure out why.

See code below. sqlString2 does not work. sqlString does. Clearly
the problem is with the nested SELECT statement. But when I copy
sqlString2 into a new query it runs just fine. Futhermore, I have
used a nested SELECT statement with the OpenRecordset() method before
and it works just fine. Any ideas?

thanks much,
jon
Here's my code:

sqlString = "SELECT [Confirmation Sent?], [Date Confirmation] " & _
"FROM [Transaction / Billing Information Info];"

'sqlString2 = "SELECT [Confirmation Sent?], [Date Confirmation] " & _
' "FROM [Transaction / Billing Information Info] " & _
' "WHERE (([Transaction ID]) In " & _
' "(SELECT [Transaction ID] FROM [qry confirmation letter] " & _
' "WHERE (([Person ID] = 26000052))));"

Debug.Print (sqlString)

Set dbs = CurrentDb
Set rs = dbs.OpenRecordset(sqlString, dbOpenDynaset)


Can you not use a single SQL string which is not dependent on another query?
In other words, replace "FROM [qry confirmation letter]"


Nov 13 '05 #4
Jon LaRosa wrote:
The reason I can't take your suggestion and create a new query rather
than use the nested SELECT statement is because that nested SELECT
statment is dynamically generated at runtime. I have removed the
references to the variable that is used there because I thought that
could be causing my problems. Unfortunately that was not the cause of
my problems.
Let's say I created a query. I do a View/SQL and the line is
Select Field1 From Table Where ThisIs That Order By HereAndThere

I could select the code from that SQL, go to my code window, and enter
strSQL = "Select Field1 " & +
"From Table " & _
"Where ThisIs That " & _
"Order By HereAndThere"

Now I have a dynamic created query at runtime.

sqlString = "SELECT [Confirmation Sent?], [Date Confirmation] " & _
"FROM [Transaction / Billing Information Info] " & _
"Inner Join [qry confirmation letter] On " & _
"[Transaction / Billing Information Info].[Transaction ID] = " & _
"[qry confirmation letter]..[Transaction ID] " & _
"WHERE [qry confirmation letter].[Person ID] = 26000052;"

Now I have created a join.
thanks for your help though.

any other ideas?


Adapt.
Nov 13 '05 #5
Sorry Salad, but I fail to see how your example is a dynamically
generated SQL statement.

Here's my full code (including the dynamic part):

------------------
sqlForReport = "SELECT [Transaction ID] FROM " & _
"[" & Me.RecordSource & "]"

If Not (IsNull(Me.Filter) Or Me.Filter = "") Then
sqlForReport = sqlForReport & " WHERE " & Me.Filter
End If

sqlString = "SELECT [Confirmation Sent?], [Date Confirmation] " & _
"FROM [Transaction / Billing Information Info] " & _
"WHERE (([Transaction ID]) In " & _
"( & sqlForReport & "));"

Set dbs = CurrentDb
Set rs = dbs.OpenRecordset(sqlString, dbOpenDynaset)
-----------------

This code appears in a report. The variable sqlForReport basically
gives me a list of transaction ID's that the report is displaying. I
don't know this ahead of time - it depends on what critera, if any,
the user chooses to view the report with (which becomes the filter).

Forgive me if I'm missing something obvious here, but I don't see how
what you posted is analagous to this situation.

thanks,
jon
Nov 13 '05 #6
Jonathan LaRosa wrote:
Sorry Salad, but I fail to see how your example is a dynamically
generated SQL statement.

Here's my full code (including the dynamic part):

------------------
sqlForReport = "SELECT [Transaction ID] FROM " & _
"[" & Me.RecordSource & "]"

If Not (IsNull(Me.Filter) Or Me.Filter = "") Then
sqlForReport = sqlForReport & " WHERE " & Me.Filter
End If

sqlString = "SELECT [Confirmation Sent?], [Date Confirmation] " & _
"FROM [Transaction / Billing Information Info] " & _
"WHERE (([Transaction ID]) In " & _
"( & sqlForReport & "));"

Set dbs = CurrentDb
Set rs = dbs.OpenRecordset(sqlString, dbOpenDynaset)
-----------------

This code appears in a report. The variable sqlForReport basically
gives me a list of transaction ID's that the report is displaying. I
don't know this ahead of time - it depends on what critera, if any,
the user chooses to view the report with (which becomes the filter).

Forgive me if I'm missing something obvious here, but I don't see how
what you posted is analagous to this situation.

thanks,
jon


"What we have here...is a failure...to communicate"

Me. I'd debug.print your SQL. Then I'd copy the printed line to the
clipboard and paste into a SQL view window and run it. I'd probably
find your error there.

I provided you a Join method in the last response that will be much
faster than your subselect. Maybe you like subselects....if so, carry
on with that method.

Generally I would create a general query in the query builder, copy to
the clipboard the SQL command, and paste into a code window and modify
it and make is dynamic as I want.

Ahhhh...I see you aren't using a subselect anymore as in the original.
And it won't work. If you are going to use the IN, the format usually
looks something like
ID In (1,2,3)
and where you use
"WHERE (([Transaction ID]) In " & _
"( & sqlForReport & "));"
will never work as you are expecting the TXID to be found in
sqlforreport which is a record set, not a list.

Hopefully someone can tell you how to do this. I would re-read what I
provided you in this thread, since the answer to your problem is there.
Nov 13 '05 #7

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

Similar topics

2
by: Not Me | last post by:
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...
11
by: MLH | last post by:
If this is what MySQL is set to... SELECT DISTINCTROW qryVehiclesNowners5.SerialNum, qryVehiclesNowners5.VDescr, qryVehiclesNowners5.Owner, qryVehiclesNowners5.VehicleJobID ,...
2
by: chris.thompson13 | last post by:
Any good advice to help solve this problem would be most welcome. I can not open a recordset based on a query (called qryNoDateSetYet). The qryNoDateSetYet uses another query within it called...
5
by: Sunnyrain | last post by:
I am developing a program in Access 2000. I couldn't make OpenRecordset method work right. It's working when I opened a simple SQL query below in OpenRecordset. ..... Dim dbs As Database, rst...
1
by: jnikle | last post by:
I have a parameter query named "qry_employee_info_reports" that I need to run in the OnOpen event of a form. I'm after its total number of records. The query's got several joins in it, and one of...
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. ...
18
by: Shawn Yates | last post by:
I have a report that looks up the earliest start time in a query . Right now it opens up the query and grabs the earliest start date like it should. This is the working code: Set rs =...
10
by: MLH | last post by:
Gentlemen: I am having one heck of a time taking a DAO walk through the records in an SQL dynaset. I'm trying to walk a set of records returned by a UNION query. I'm attempting to filter the...
12
by: dtsmith1984 | last post by:
I have a form that i want to be able to reassign a specific piece of software to a different machine. Form specs: Software Title: cbotitle CDKEY: cbocdkey Old Assignment: cbooldassignment New...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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
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...

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.