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

Too Few Parameters. Expected 1 (Recordset/Query)

121 100+
Hi,

I get the Too Few Parameters. Expected 1 error message when i run the following code
Expand|Select|Wrap|Line Numbers
  1. Set dbsClient = CurrentDb
  2.     Set rstCheck = _
  3.     dbsClient.OpenRecordset("Q_SelEquipTmpTbl", dbOpenDynaset)
I am referencing a combo box on a form in the query criteria
Expand|Select|Wrap|Line Numbers
  1. Like [Forms]![F_EquipBooking].[SF_EquipBooking]![SFEquipID]
when i take the reference to the combo box out of the query it works.

please help

Regards Phill
May 1 '08 #1
9 5230
ADezii
8,834 Expert 8TB
Hi,

I get the Too Few Parameters. Expected 1 error message when i run the following code

Set dbsClient = CurrentDb
Set rstCheck = _
dbsClient.OpenRecordset("Q_SelEquipTmpTbl", dbOpenDynaset)

I am referencing a combo box on a form in the query criteria

Like [Forms]![F_EquipBooking].[SF_EquipBooking]![SFEquipID]

when i take the reference to the combo box out of the query it works.

please help

Regards Phill
There is obviously a problem resolving the single Query Parameter. You can always Open the Recordset directly from the SQL in Q_SelEquipTmpTbl, namely:
Expand|Select|Wrap|Line Numbers
  1. Dim MySQL As String
  2. Dim MyDB As DAO.Database
  3. Dim MyRS As DAO.Recordset
  4.  
  5. 'Assuming [SFEquipID] is Numeric     
  6. MySQL = "SQL from Q_SelEquipTmpTbl with the WHERE Clause similar to [SomeField] Like " & _
  7. [Forms]![F_EquipBooking].[SF_EquipBooking]![SFEquipID]
  8.  
  9. Set MyDB = CurrentDb()
  10. Set MyRS = MyDB.OpenRecordset(MySQL, dbOpenDynaset)
May 1 '08 #2
NeoPa
32,556 Expert Mod 16PB
As a matter of interest, post what you get running the following SQL (in the same circumstances where you get the above error running your query) :
Expand|Select|Wrap|Line Numbers
  1. SELECT [Forms]![F_EquipBooking].[SF_EquipBooking]![SFEquipID]
You will have to run it from the SQL view as it (run) won't be available from any other view.
May 1 '08 #3
ADezii
8,834 Expert 8TB
As a matter of interest, post what you get running the following SQL (in the same circumstances where you get the above error running your query) :
Expand|Select|Wrap|Line Numbers
  1. SELECT [Forms]![F_EquipBooking].[SF_EquipBooking]![SFEquipID]
You will have to run it from the SQL view as it (run) won't be available from any other view.
Hello NeoPa, I could be wrong but I think that the problem is a little more sinister than it actually appears. I don't think that you can create a Traditional Recordset on a QueryDef Object whose Parameter is a Control on a Form/Sub-Form. I don't think that it can be resolved in this fashion. The code in Post #2, however, will work and also the code posted below, as long as the Like Operator is not utilized. As always, let me know what you think - I'm probably wrong, anyway, ergo not directing the Reply to the OP. (LOL).
Expand|Select|Wrap|Line Numbers
  1. NOTE: The actual Prompt you use in Q_SelEquipTmpTbl is irrelevant, since the only Parameter is indicated by an Index, and not a literal String Value
  2.  
  3. Dim dbsClient As DAO.Database
  4. Dim rstCheck As DAO.Recordset
  5. Dim qdf As DAO.QueryDef
  6.  
  7. Set dbsClient = CurrentDb()
  8. Set qdf = dbsClient.QueryDefs("Q_SelEquipTmpTbl")
  9.  
  10. qdf.Parameters(0) = [Forms]![F_EquipBooking].[SF_EquipBooking]![SFEquipID]
  11.  
  12. Set rstCheck = qdf.OpenRecordset(dbOpenDynaset, dbReadOnly)
  13.  
  14. Do While Not rstCheck.EOF
  15.   'Loop code here, set to Read Only
  16.   rstCheck.MoveNext
  17. Loop
  18.  
  19. rstCheck.Close
  20. Set rstCheck = Nothing
May 2 '08 #4
NeoPa
32,556 Expert Mod 16PB
ADezii, You posted the same thing twice so I deleted the first one.

The SQL I suggested should work. It's a little weird I know but give it a try ;)

It's not to fix the problem though. Simply to provide some information and hopefully identify what might NOT be the problem.
May 2 '08 #5
ADezii
8,834 Expert 8TB
ADezii, You posted the same thing twice so I deleted the first one.

The SQL I suggested should work. It's a little weird I know but give it a try ;)

It's not to fix the problem though. Simply to provide some information and hopefully identify what might NOT be the problem.
You posted the same thing twice so I deleted the first one.
Thanks NeoPa
The SQL I suggested should work.
The SQL you posted will definately work. What I was referring to was the OP's logic, namely: Creating a Recordset on a Query whose Criteria is a Control on a Sub-Form.
May 2 '08 #6
NeoPa
32,556 Expert Mod 16PB
... namely: Creating a Recordset on a Query whose Criteria is a Control on a Sub-Form.
Although I very rarely use that concept myself (I build up SQL strings in VBA where possible), I know that most people seem to use that as a standard way of filtering on selected (form) items. I think that's what you're referring to. Excuse me if I've misunderstood again.

For it to work, the reference must be an absolute one (usually means using the Forms() collection). This is because the SQL engine (processor) is not executing from within the current code but is independent of it.
May 2 '08 #7
phill86
121 100+
Hello NeoPa, I could be wrong but I think that the problem is a little more sinister than it actually appears. I don't think that you can create a Traditional Recordset on a QueryDef Object whose Parameter is a Control on a Form/Sub-Form. I don't think that it can be resolved in this fashion. The code in Post #2, however, will work and also the code posted below, as long as the Like Operator is not utilized. As always, let me know what you think - I'm probably wrong, anyway, ergo not directing the Reply to the OP. (LOL).
Expand|Select|Wrap|Line Numbers
  1. NOTE: The actual Prompt you use in Q_SelEquipTmpTbl is irrelevant, since the only Parameter is indicated by an Index, and not a literal String Value
  2.  
  3. Dim dbsClient As DAO.Database
  4. Dim rstCheck As DAO.Recordset
  5. Dim qdf As DAO.QueryDef
  6.  
  7. Set dbsClient = CurrentDb()
  8. Set qdf = dbsClient.QueryDefs("Q_SelEquipTmpTbl")
  9.  
  10. qdf.Parameters(0) = [Forms]![F_EquipBooking].[SF_EquipBooking]![SFEquipID]
  11.  
  12. Set rstCheck = qdf.OpenRecordset(dbOpenDynaset, dbReadOnly)
  13.  
  14. Do While Not rstCheck.EOF
  15.   'Loop code here, set to Read Only
  16.   rstCheck.MoveNext
  17. Loop
  18.  
  19. rstCheck.Close
  20. Set rstCheck = Nothing
Hi ADezii

its sorted thanks for your help

Cheers Phill
May 2 '08 #8
phill86
121 100+
As a matter of interest, post what you get running the following SQL (in the same circumstances where you get the above error running your query) :
Expand|Select|Wrap|Line Numbers
  1. SELECT [Forms]![F_EquipBooking].[SF_EquipBooking]![SFEquipID]
You will have to run it from the SQL view as it (run) won't be available from any other view.
Hi NeoPa,

Thanks its sorted

Cheers Phill
May 2 '08 #9
NeoPa
32,556 Expert Mod 16PB
Good for you Phill, and thanks for letting us know :)
May 2 '08 #10

Sign in to post your reply or Sign up for a free account.

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...
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
3
by: Ryan Hubbard | last post by:
I would like to run a query from VBA. The query will be one with parameters. Is there a way to run the query and have Access prompt for the values like it does if I where to execute it through...
7
by: Zlatko Matić | last post by:
Let's assume that we have a database on some SQL server (let it be MS SQL Server) and that we want to execute some parameterized query as a pass.through query. How can we pass parameters to the...
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,...
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...
3
by: phill86 | last post by:
Hi, I am trying to run the following query in a recordset and i get the following error message Runtime error 3061 - Too few parameters. Expected 1 i am using the following code
18
by: JGrizz | last post by:
Greetings, I first off want to state that I am new to the forum, so if this question ends up in the wrong area, I apologize. This pertains to Access 2003/VBA/SQL issues... I have been doing some...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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.