Solved

Too few parameters. Expected 1.

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

803 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