Solved

Too few parameters. Expected 1.

Posted on 2008-10-30
3
903 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 250 total points
ID: 22842531
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 58

Assisted Solution

by:Jim Dettman (Microsoft MVP/ EE MVE)
Jim Dettman (Microsoft MVP/ EE MVE) earned 250 total points
ID: 22842550
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
ID: 31511723
Thanks :) Only fair I split the points. Appreciate the replies.
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

690 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