Solved

Too few parameters. Expected 1.

Posted on 2008-10-30
3
902 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 57

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

726 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