473,394 Members | 1,865 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

UPDATE Syntax not working

129 100+
Hi i have this code that Adds data into a Purchase Order Header, then displays the PONumber in a Message Box and finally Updates the PONo within the Order made which can be many records. The code i have is as follows;

Expand|Select|Wrap|Line Numbers
  1. Set db = CurrentDb()
  2.     Set rst = db.OpenRecordset("SELECT * FROM pordhdr")
  3.  
  4.     With rst
  5.         .AddNew
  6.         !SuppNo = Me.txtSuppNo
  7.         !PODate = [Forms]![frmCustomerOrderForm]![sfrmSOHeader]![OrderDate]
  8.         !DueDate = [Forms]![frmCustomerOrderForm]![sfrmSOHeader]![DueDate]
  9.         .Update
  10.     End With
  11.  
  12.     'Find the NEW PONo just Assigned to the pordhdr
  13.     'Display Message with PONo Created
  14.  
  15.     rst.MoveLast
  16.         POMsg = MsgBox("Purchase Order " & rst!PONo & " Has Been Created. ", vbOKOnly, "Purchase Order Created")
  17.  
  18.     'UPDATE the PONo Field (Based on SuppNo and OrderNo with the last PONo above) within the ordlin Table therefore Assigning the Stock Details with a Purchase Order
  19.  
  20.     Set rst2 = db.OpenRecordset("SELECT * FROM ordlin")
  21.  
  22.     rst2.Edit
  23.     strSQL = "UPDATE ordlin SET [PONo] = '" & rst!PONo & "' WHERE ([ordlin.OrderNo] = [forms]![frmPOGenerator]![txtOrderNo] And [ordlin.SuppNo] = [forms]![frmPOGenerator]![txtSuppNo] AND ((ordlin.PONo) Is NULL))"
  24.     DoCmd.RunSQL strSQL
  25.     rst2.Update
  26.  
  27.     rst.Close
  28.     rst2.Close
I have tested the code line by line and its works upto the point of the Update part starting with rst2.

Can anybody tell me why it doesn't update the ordlin table. No errors occur! Thanks in advance.
Oct 10 '08 #1
2 1276
puppydogbuddy
1,923 Expert 1GB
try this syntax. Have assumed all form controls referenced are text data types.
Expand|Select|Wrap|Line Numbers
  1. strSQL = "UPDATE ordlin SET [PONo] = '" & rst!PONo  & "' & " WHERE ([ordlin.OrderNo] = '" & [forms]![frmPOGenerator]![txtOrderNo] & "' & " And [ordlin.SuppNo] = '" & [forms]![frmPOGenerator]![txtSuppNo] & "' & " AND ((ordlin.PONo) Is NULL))"
Oct 10 '08 #2
Stewart Ross
2,545 Expert Mod 2GB
Constantine Al, I think we have commented before that you are unnecessarily mixing recordset processing with SQL updates, making it difficult to understand what is going on. The SQL update in lines 23 and 24 has no relation whatsoever to the rst2 lines immediately before and after. It does not need them and it will work (or not) just as well without them.

As for what is wrong, it is impossible to say at this juncture without you telling us what you have tested, and the conditions immediately before and after your update that is apparently not working. Otherwise we are just guessing I'm sorry to say.

-Stewart
Oct 10 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Dave | last post by:
I have 2 tables, one with names, and another with addresses, joined by their CIVICID number (unique to the ADDRESSINFO table) in Oracle. I need to update a field in the NAMEINFO table for a...
3
by: Alex | last post by:
Hi folks, Hopefully this is a simple fix, but I keep getting Syntax error with this statement in an MS SQL DTS statement and in Query Analyzer: Update A Set A.deptcode = A.deptcode, A.type =...
5
by: S.Patten | last post by:
Hi, I have a problem with updating a datetime column, When I try to change the Column from VB I get "Incorrect syntax near '942'" returned from '942' is the unique key column value ...
8
by: Lauren Quantrell | last post by:
In VBA, I constructed the following to update all records in tblmyTable with each records in tblmyTableTEMP having the same UniqueID: UPDATE tblMyTable RIGHT JOIN tblMyTableTEMP ON...
17
by: kalamos | last post by:
This statement fails update ded_temp a set a.balance = (select sum(b.ln_amt) from ded_temp b where a.cust_no = b.cust_no and a.ded_type_cd = b.ded_type_cd and a.chk_no = b.chk_no group by...
17
by: Benoit Martin | last post by:
I'm working on a project in VB.net connecting to a SQL Server 2000 database that I can't modify I created a dataset with a schema identical to the DB. When trying to update the DB from the dataset...
5
by: HydroSan | last post by:
Having a bit of a problem getting UPDATE working. The project in question is a simple MySQL VB.NET frontend, allowing Insertion, Selection, and others. Well, I've gotten Drop and Insert working,...
6
by: FayeC | last post by:
I really need help figuring this out. i have a db with mostly text fields but 2. The user_id field is an autonumber (key) and the user_newsletter is a number (1 and 0) field meaning 1 yes the ...
8
by: Stephen Plotnick | last post by:
I have three forms and update one table in an Access DB with sucess in one form. In the other two forms I'm trying to do an update to a different table in the Access DB. The error I'm getting...
2
by: Looch | last post by:
Hi, I'm filling a GridView with a simple sproc select statement. I'm trying to use the Update tab to create an update statement and using the following: Update Shipping_Requests Set Shipped...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.