Solved

Too few parameters. Expected 1.

Posted on 2008-10-30
3
899 Views
Last Modified: 2013-11-28
Hi,

I'm always having problems with SQL queries and WHERE statements. I know it's the syntax which is wrong. If you can tell me what's wrong with the query I would be very grateful. I know I can shorten the control to me!<blah> but I tried using a query to do what I wanted and used the full syntax from that but it didn't work out too well.

Basically I'm trying to subtract one from the InStock field in the Inventory field where the barcode in the inventory table = the txtBarCode1 text field on the form.

This code is executed from a command button.

Also if you have any usful guides or FAQs about SQL statements that you could point me at that would be great.

Thanks in advance :)
Set dbTransaction = DBEngine.Workspaces(0).Databases(0)

        Set rsInventory = dbTransaction.OpenRecordset("SELECT InStock FROM tblInventory WHERE (((tblInventory.BarCode)=[Forms]![frmOrderItems]![txtBarCode1]));")

        With rsInventory

            .Edit

                !InStock = !InStock - 1

                .Update

        End With

            rsInventory.Close

        Set rsInventory = Nothing

            dbTransaction.Close

        Set dbTransaction = Nothing

Open in new window

0
Comment
Question by:itmtsn
3 Comments
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 250 total points
Comment Utility
i'll assume that barcode is text Data type

        Set rsInventory = dbTransaction.OpenRecordset("SELECT InStock FROM tblInventory WHERE tblInventory.BarCode='" & [Forms]![frmOrderItems]![txtBarCode1] &"'")
0
 
LVL 57

Assisted Solution

by:Jim Dettman (Microsoft MVP/ EE MVE)
Jim Dettman (Microsoft MVP/ EE MVE) earned 250 total points
Comment Utility
You need to change this:

        Set rsInventory = dbTransaction.OpenRecordset("SELECT InStock FROM tblInventory WHERE (((tblInventory.BarCode)=[Forms]![frmOrderItems]![txtBarCode1]));")

to

        Set rsInventory = dbTransaction.OpenRecordset("SELECT InStock FROM tblInventory WHERE tblInventory.BarCode= " & [Forms]![frmOrderItems]![txtBarCode1] & ";")

  and make sure that frmOrderItems is open at the time you execute this and that txtBarCode1 is a valid control on the form.

  Also, if BarCode is a text field, then you need to do this for the statement:


        Set rsInventory = dbTransaction.OpenRecordset("SELECT InStock FROM tblInventory WHERE tblInventory.BarCode= '" & [Forms]![frmOrderItems]![txtBarCode1] & "';")

   As far as learning SQL, one good trick is to do it in the query designer graphically, then click the SQL button to see the resulting SQL.

JimD.
0
 

Author Closing Comment

by:itmtsn
Comment Utility
Thanks :) Only fair I split the points. Appreciate the replies.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now