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
Solved

Too few parameters. Expected 1.

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most pā€¦
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which ā€¦
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

839 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