Solved

Help with Access SQL Statement

Posted on 2009-05-07
3
230 Views
Last Modified: 2012-05-06
I have an event procedure within an Access application that has the following query:

DoCmd.RunSQL "Delete * FROM [Payments] WHERE [Payments].OrderID = [Orders].OrderID AND [Orders].CustomerID = " & CustomerNumber & ";"

When it gets to this statement, it keeps prompting me for "[Orders].OrderID".  Orders is a table in the database, and OrderID is the Primary key in that table.

for the life of me I cannot see what is wrong with this statement.

Can someone please help.

Thanks...Tom
0
Comment
Question by:tpigielski
[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 13

Expert Comment

by:usachrisk1983
ID: 24332752
But it doesn't know what [orders].orderid is.  I suspect that it's a field on your form somewhere?  If so, use the control name instead.  You'll need to do the same for the other items in your WHERE clause.
0
 
LVL 25

Accepted Solution

by:
lwadwell earned 250 total points
ID: 24332789
Hi tpigielski,

Is this what you want?

DoCmd.RunSQL "Delete * FROM [Payments] WHERE [Payments].OrderID IN (SELECT [Orders].OrderID FROM [Orders] WHERE [Orders].CustomerID = " & CustomerNumber & ");"


lwadwell
0
 
LVL 6

Expert Comment

by:BALMUKUND KESHAV
ID: 24333137
Do hope there must be a textbox/combo box having data of orders.orderid , customerid, put that control instead of orders.orderid, if your textbox/combo box havign data of orders,orderid is txtorderid and customerid is txtcustomerid, then use the sql qry like this :

DoCmd.RunSQL "Delete * FROM [Payments] WHERE [Payments].OrderID = txtorderid AND [Payments].customerid = " & CustomerNumber & ";"

Bm keshav
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

As they say in love and is true in SQL: you can sum some Data some of the time, but you can't always aggregate all Data all the time! Introduction: By the end of this Article it is my intention to bring the meaning and value of the above quote to…
If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

737 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