473,397 Members | 2,068 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

133 100+
I have a SQL statement to call data using a form. however, it keeps generating a "[3061]: Too few parameters. Expected 1" error.

I've attempted to convert it to queryDef, however, no progress has been made.

Any guidance, would be appreciated.

the original code is as such:

Expand|Select|Wrap|Line Numbers
  1. Dim dbs As DAO.Database
  2. Dim rstTemp As DAO.Recordset
  3. Dim strSQL As String
  4.  
  5. Set dbs = CurrentDb()
  6.  
  7. '**** create output table
  8. 'Delete temporary table
  9. 'DoCmd.RunSQL "DROP TABLE tbl_MktPOsHash;"
  10.  
  11. strSQL = "SELECT FIMSMGR_FTVACCI.FTVACCI_FUND_CODE, " & _
  12.                                 "tbl_MktPOs.Date, " & _
  13.                                 "tbl_MktPOs.PO, " & _
  14.                                 "tbl_MktPOs.POAmt, " & _
  15.                                 "tbl_MktPOs.BlnkWvr, " & _
  16.                                 "tbl_MktPOs.SC, " & _
  17.                                 "tbl_MktPOs.Buyer, " & _
  18.                                 "tbl_MktPOs.Desc, " & _
  19.                                 "tbl_MktPOs.PO_Originated, " & _
  20.                                 "tbl_MktPOs.Index, " & _
  21.                                 "tbl_MktPOs.CORD_No, " & _
  22.                                 "tbl_MktPOs.BuyerUserName, " & _
  23.                                 "tbl_MktPOs.BuyerLastName, " & _
  24.                                 "tbl_MktPOs.BuyerFirstName, " & _
  25.                                 "tbl_MktPOs.BuyerMkt, " & _
  26.                                 "tbl_MktPOs.[Replenishment Order], " & _
  27.                                 "tbl_MktPOs.[Contract Name], " & _
  28.                                 "tbl_MktPOs.[Contract No], " & _
  29.                                 "tbl_MktPOs.[Contract Expiration Date] " & _
  30.         "FROM tbl_MktPOs " & _
  31.         "INNER JOIN FIMSMGR_FTVACCI " & _
  32.         "ON tbl_MktPOs.Index = FIMSMGR_FTVACCI.FTVACCI_ORGN_CODE " & _
  33.         "WHERE (((FIMSMGR_FTVACCI.FTVACCI_FUND_CODE) Like 'R*') AND " & _
  34.                                 "((FIMSMGR_FTVACCI.FTVACCI_NCHG_DATE)=#12/31/2099#) AND " & _
  35.                                 "((tbl_MktPOs.BlnkWvr) Like 'W' & [Forms]![F_Waiver_Yr]![Txt_Waiver_Yr] & '*B-001'));"
  36.  
  37. Set rstTemp = dbs.OpenRecordset(strSQL)
** Edit **

even if quotes singles are placed around the form value, the query will run but returns no records.

Expand|Select|Wrap|Line Numbers
  1. "WHERE (((FIMSMGR_FTVACCI.FTVACCI_FUND_CODE) Like 'R*') AND " & _
  2.                                 "((FIMSMGR_FTVACCI.FTVACCI_NCHG_DATE)=#12/31/2099#) AND " & _
  3.                                 "((tbl_MktPOs.BlnkWvr) Like 'W' & '[Forms]![F_Waiver_Yr]![Txt_Waiver_Yr]' & '*B-001'));"
Oct 17 '11 #1
13 1354
NeoPa
32,556 Expert Mod 16PB
I assume the line that causes the error message is #37. It's always a good idea to say so though. This then, is a SQL problem. I'm away from my PC ATM so I can't link you to a thread that explains why posting VBA for a SQL problem is not very helpful, but assume I have (I may add it later as it includes other tips to save you time dealing with SQL problems and is worth reviewing anyway).

For now though, I'll just say you need to post the actual SQL you're having issues with rather than the VBA code you create it with. That way we're not doing double the work.

Frankly, I don't see anything obviously causing the issue, but the change from the previous version is an indication that your reference is the cause of your problem. Seeing the actual resultant SQL would be a a lot more useful though, and may answer questions I have about what may be going wrong (It will at least indicate what is used in the value of that control when it goes wrong).

BTW FYI Adding the quotes provided information, but is not remotely part of any solution.
Oct 17 '11 #2
dowlingm815
133 100+
i'm not sure i follow your direction. the issue is on line 36 at the "where" clause when the form parameters are reference.
Oct 17 '11 #3
NeoPa
32,556 Expert Mod 16PB
No. Actually it's not. Line #36 is simply an extension of line #11 - an assignment of various values to a string called strSQL. There is nothing wrong with this per se. In effect the only requirement here is that the value is a string. There is only a problem when you try to use the value, then stored in strSQL, in line #37 (where it must be of valid SQL format).

That is where your problem occurs. I expect your error essage would have made that clear (When you choose to debug then that line will be highlighted in yellow). I make mistakes, as we all do, but it would make more sense for you to assume I know what I'm talking about until shown otherwise.

I still need from you what I requested in my earlier post (#2) - The value of strSQL at the point where it is about to be used (Line #37).
Oct 17 '11 #4
Rabbit
12,516 Expert Mod 8TB
The problem is how you're referencing the control on the form. You can't reference it from within OpenRecordset. It has to be outside of the quotes.
Oct 17 '11 #5
dowlingm815
133 100+
NeoPa, the value is 12.

Rabbit, the quotes have been removed.
Oct 17 '11 #6
Rabbit
12,516 Expert Mod 8TB
I didn't say remove the quotes. I said it needs to be outside of the quotes, i.e. not part of the string at all. But rather pass in the literal value.
Oct 17 '11 #7
NeoPa
32,556 Expert Mod 16PB
DowlingM:
NeoPa, the value is 12.
The value of strSQL is a great big long SQL string.

The link I intended to post earlier is How to Debug SQL String, and it seems it would be very much worth your while to check it out.
Oct 17 '11 #8
NeoPa
32,556 Expert Mod 16PB
Rabbit:
I didn't say remove the quotes. I said it needs to be outside of the quotes, i.e. not part of the string at all. But rather pass in the literal value.
I'm not sure that expresses your thinking very clearly Rabbit. If I don't misunderstand you then you are suggesting that the reference to the control be replaced with a literal value representing the control, which is added into the calculation of strSQL outside of the other literal strings. Something like :
Expand|Select|Wrap|Line Numbers
  1. strSQL = "SELECT ... WHERE [X] = " & Me.Control
When the control is set at 12 this would result in the string :
Expand|Select|Wrap|Line Numbers
  1. "SELECT ... WHERE [X] = 12"
This string value would then be passed to the SQL engine to be processed. This would also work of course, but control references are possible in SQL.
Oct 17 '11 #9
Rabbit
12,516 Expert Mod 8TB
When I tried it with OpenRecordset, referencing the control within the string resulted in the same error.
Oct 17 '11 #10
NeoPa
32,556 Expert Mod 16PB
I assume you're referring to the first version (without the reference in quotes). You don't say which level of string you had in mind. Tell me if I misunderstand you.

I just tried a very simple test in a Query and ran :
Expand|Select|Wrap|Line Numbers
  1. SELECT Forms!frmClipboard.txtCategory
while the form [frmClipboard] was open and the TextBox [txtCategory] (of the currently selected record) held the value "Link". This is exactly what I got as a single record result.

I just rechecked in exactly the same way but with :
Expand|Select|Wrap|Line Numbers
  1. SELECT Forms!frmClipboard!txtCategory
It didn't work.

NeoPa:
This would also work of course, but control references are possible in SQL.
I didn't say the reference was correct, just that references are possible. I felt that was something we would better look into when the OP had posted the information (SQL string) properly (at which point I would have done this testing to verify exactly what did and didn't work). I didn't feel it appropriate to go to that level with only VBA to work with.
Oct 17 '11 #11
Rabbit
12,516 Expert Mod 8TB
I'm guessing you tried it in a query def? That should work. Try it in OpenRecordset, it stops working. I don't know why but it seems to render things differently when you use it in a query def as opposed to OpenRecordset.
Oct 17 '11 #12
NeoPa
32,556 Expert Mod 16PB
It seems bizarre, but you're absolutely correct (Not bizarre that you're correct, but bizarre what you're correct about)!

I tried various flavours, but that error message certainly indicates that the reference is not recognised. I don't believe there are any potentially viable forms of the reference I didn't try - but all to no avail. It certainly seems that such references are invalid when used within the OpenRecordset() method (although the Help system gives no clues of such inconsistent behaviour either).

@DowlingM
This confirms what Rabbit suggested in post #5 (clarified further in my post #9). Let us know if this is enough to get you going with.
Oct 17 '11 #13
Stewart Ross
2,545 Expert Mod 2GB
Access has always had a bit of a split personality when it comes to interpreting form controls as parameters.

This link to a SmartAccess article for A2003 on the MS site below provides a good explanation of why the error occurs. In summary, the Jet database engine is invoked in two different contexts. When invoked from code it appears that the user interface is not invoked by Jet to resolve the missing parameter, which is otherwise done automatically when running from the usual forms/reports/queries interface.

MS's knowledgebase articles, like the SmartAccess article, suggest setting the missing form parameter by appending to a suitable qdef in code (see this knowledgebase article for example).

-Stewart
Oct 18 '11 #14

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

Similar topics

6
by: Miranda | last post by:
Hello, could somebody please help me figure this error out. I'm at my wits end here. This is my connection & SQL statement: <%@Language="Javascript" %> <!--#include...
8
by: kbrad | last post by:
I am using the following code in asp to select some data from an access db. recSel is defined and set further up my webpage, as is rsUpdate User. I cannot work out how to get past this error...
2
by: nub | last post by:
Using this exact query: ------------------------------- SELECT ProductName, count(ProductName) as Quantity, sum(TotalPrice) as Total FROM OrderDetails GROUP BY ProductName ORDER BY Total DESC ...
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
8
by: RC | last post by:
In my Access 2002 form, I have a combo box and on the AfterUpdate event I use DoCmd.RunSQL ("UPDATE .... to update records in a table. When it starts to run I get a message "You are about to...
1
by: bonnie.tangyn | last post by:
Hello all I get Too few parameters expected 2 error and "The MS Jet Database engine cannot find the input table or query "myTempTablename". Make sure it exists and that its name is spelled...
1
by: Punker | last post by:
Hi guys, I am trying to create export specifications for one of my queries. Now when I run the query on its own, it works perfectly. However when I try to export the data I get back the error...
6
by: Michael R | last post by:
Please help me with this. I have a form in which I would like to present results from a CrossTab query in a subform. I don't need the query to be bounded to a master field. Also, I have a...
1
by: TheGuyKnownAsY | last post by:
Hi everyone, I'm new here. My problem: the parameters that appear after rs.open when oppening the SQL connection. Microsoft OLE DB Provider for ODBC Drivers error '80040e10' Too few...
1
by: ryan langley | last post by:
I have a access query which i filter using 3 combo boxes within a form (day, location, id). I have created a function to populate a access email with email addresses form the query this worked fine...
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: 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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
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.