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

Too few parameters expected 1

I currently have a listbox in one of my forms, when selected and delete is pressed i wish to delete this item from the list .
This is what i have been trying
Expand|Select|Wrap|Line Numbers
  1.  If MsgBox("Would you like to delete?", vbYesNo, "Confirmation") = vbYes Then
  2.     Set rstDeleteorderlibe = CurrentDb.OpenRecordset("SELECT * FROM tblorderlist WHERE productID = " & 1stlistbox
  3.         rstDelete.Delete
  4.         rstDelete.Close
  5. End if
  6.  
an error message is being displayed suggesting
too few parameters expected 1.

Would anyone know what that means.?
Feb 16 '08 #1
9 5067
missinglinq
3,532 Expert 2GB
First off, you're missing a closing parenthesis

Set rstDeleteorderlibe = CurrentDb.OpenRecordset("SELECT * FROM tblorderlist WHERE productID = " & 1stlistbox)

Try adding that and see what happens.

Linq ;0)>
Feb 16 '08 #2
sierra7
446 Expert 256MB
Hi
I think it means you have missed a bracket off the end of your OpenRecordset command ! (and Access is at a loss to interprete what you want)

Incidentally, the rules are that you should use 'tags' around your code. One advantage is that it is clearer to read and your lines will be numbered so it is easier to reference.

On second reading I am a bit confused because you seem to have two recordsets "rstDeleteorderlibe" and "rstDelete". If you settle on one name then I think your code should run but personally I would not involve recordsets and just use SQL.
Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunSQL "DELETE * FROM tblorderlist WHERE productID = " & 1stlistbox
Normally, Access will warn you how many records are to be deleted and request confirmation. If you don't want this for your users you can toggle warning off then on again.
Expand|Select|Wrap|Line Numbers
  1.  
  2. 'turn off warnings
  3. Application.SetOption "Confirm Action Queries", False
  4.  
  5. DoCmd.RunSQL "DELETE * FROM tblorderlist WHERE productID = " & 1stlistbox
  6.  
  7. 'turn on warnings
  8. Application.SetOption "Confirm Action Queries", True
  9.  
S7
Feb 16 '08 #3
Hi

I have placed a bracket and the end of the open recordset but the same error remains


Hi
I think it means you have missed a bracket off the end of your OpenRecordset command ! (and Access is at a loss to interprete what you want)

Incidentally, the rules are that you should use 'tags' around your code. One advantage is that it is clearer to read and your lines will be numbered so it is easier to reference.

On second reading I am a bit confused because you seem to have two recordsets "rstDeleteorderlibe" and "rstDelete". If you settle on one name then I think your code should run but personally I would not involve recordsets and just use SQL.
Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunSQL "DELETE * FROM tblorderlist WHERE productID = " & 1stlistbox
Normally, Access will warn you how many records are to be deleted and request confirmation. If you don't want this for your users you can toggle warning off then on again.
Expand|Select|Wrap|Line Numbers
  1.  
  2. 'turn off warnings
  3. Application.SetOption "Confirm Action Queries", False
  4.  
  5. DoCmd.RunSQL "DELETE * FROM tblorderlist WHERE productID = " & 1stlistbox
  6.  
  7. 'turn on warnings
  8. Application.SetOption "Confirm Action Queries", True
  9.  
S7
Feb 17 '08 #4
Scott Price
1,384 Expert 1GB
What line is highlighted when you get this error message?

The Delete method when used with a Recordset like you are doing deletes the currently selected record in the recordset only.

I see at least four problems in your code as it stands in the first post.

1. You are referring to two different recordsets in the same bit of code.

2. You need to move to a specific record before using the .Delete method

3. You appear to be trying to use the .Delete method to delete more than one record at the same time, which it will not allow.

4. Why are you using recordsets, when as Sierra has already said, the DoCmd.RunSQL is much simpler and cleaner?

Regards,
Scott
Feb 17 '08 #5
Scott Price
1,384 Expert 1GB
I just checked again in one of my databases where I am using a command button to delete selected items from a multiselect listbox, and I use the DoCmd.RunSQL method there.

Also, thanks Sierra for the tip about Application.SetOptions! I've always used the generic DoCmd.SetWarnings False, which has the disadvantage of turning ALL warnings off, where the SetOptions "Confirm Action Queries" is more specific. I like it already :-)

Regards,
Scott
Feb 17 '08 #6
sierra7
446 Expert 256MB
2. You need to move to a specific record before using the .Delete method

3. You appear to be trying to use the .Delete method to delete more than one record at the same time, which it will not allow.

Scott
Well spotted Scott !

Unless Goldstar does a rstDelete.MoveFirst he is unlikely to delete anything because as you say there is unlikely to be a current record.

Then if there are more than one record it will require code to MoveNext and loop until all are gone. i.e. when rstDelete.BOF = True and rstDelete.EOF = True.

S7
Feb 17 '08 #7
Scott Price
1,384 Expert 1GB
I strongly suspicion that the error message he's getting is from not setting the current record in the recordset.

That's why I asked which line was highlighted in the debugger.

The parameter that it's expecting with the delete command is a currently selected record, which in this instance is null making for a missing parameter with the .Delete method.

I still think it's easier and cleaner to use the DoCmd.RunSQL approach, but we'll wait to see what the OP decides before going further with anything :-)

Regards,
Scott
Feb 17 '08 #8
Thanks for all the info it helped me resolve that, a bit late response, too much things going on at once....


but im getting another too few parameters expected 1 but this time i have used brackets, i like using this method as i feel comfortable and with not much experience it gets me through. any help would be appreciated

dbase.Execute ("UPDATE tblitem SET isselected = False WHERE hireno = '" & lsttransaction & "'")

This is updating my table items by setting the selecting item to false when the hireno equals the 1sttransaction.

It must be a bug to see the same question reappear, but im new to this game and i really appreciate all the help
Mar 5 '08 #9
sierra7
446 Expert 256MB
Hi

I am assuming that you have set-up the 'dbase' object correctly so you are just trying to execute an SQL string.

Your SQL looks ok (it's missing a final semicolon but that might be ok), so long as [hireno] is a character field not a number. If it was a number you would not need the quotes around [lsttransaction ] so your code would be;-

Expand|Select|Wrap|Line Numbers
  1. dbase.Execute ("UPDATE tblitem SET isselected = False WHERE hireno = " & lsttransaction & ";")
S7
Mar 6 '08 #10

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

Similar topics

11
by: Andrew Thompson | last post by:
I have written a few scripts to parse the URL arguments and either list them or allow access to the value of any parameter by name. <http://www.physci.org/test/003url/index.html>...
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...
2
by: Patrick Olurotimi Ige | last post by:
I converted the code below from VB.NET to C# cos i have to add it to a C# application!! But i'm getting the error:- System.Data.SqlClient.SqlCommand.Parameters' denotes a 'property' where a...
14
by: cody | last post by:
I got a similar idea a couple of months ago, but now this one will require no change to the clr, is relatively easy to implement and would be a great addition to C# 3.0 :) so here we go.. To...
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,...
4
by: HeislerKurt | last post by:
I'm getting the infamous error, "Too few parameters. Expected 2", when executing an update SQL statement in VBA. I assume it's a SQL syntax issue, but I can't find the problem, and I used a VBA...
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...
5
by: mnarewec | last post by:
Hi folks, I want to create a procedure where by it will take a sqlcommand, a string, and property. I want to use this procedure to add parameters to my sql command of type stored procedures since I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
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
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,...
0
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...

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.