Click here to Skip to main content
15,890,609 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
'Updating AdjustmentHead & AdjustmentDetails
'-------------------------------------------

'update AdjustmentHead
strSql = "UPDATE AdjustmentHead SET AdjustmentHead.[Adjustment+V] = " & Forms![AdjustmentHead]![Adjustment+V] & ", AdjustmentHead.[Adjustment-V] = " & [Forms]![AdjustmentHead]![Adjustment-V2] & ", AdjustmentHead.AdjustmentStatus = -1, AdjustmentHead.AdjTransactionID = " & intTransactionID & ", AdjustmentHead.AdjOrderID = '" & strOrderID & "'"
strSql = strSql & " WHERE (((AdjustmentHead.AdjustmentHeadID)=[Forms]![AdjustmentHead]![AdjustmentHeadID]));"
DoCmd.RunSQL strSql

'update Adjustment
strSql = "UPDATE AdjustmentDetailsQ INNER JOIN Items ON AdjustmentDetailsQ.ItemID = Items.ItemID SET Items.[In] = [Items]![In]+[AdjustmentDetailsQ]![OrderQty], Items.Out = [Items]![Out]+[AdjustmentDetailsQ]![IssueForLocal]+[AdjustmentDetailsQ]![IssueForForign], Items.CIN = [Items]![CIN]+[AdjustmentDetailsQ]![OrderCQty], Items.COut = [Items]![COut]+[AdjustmentDetailsQ]![IssueForLocal]"
strSql = strSql & " WHERE (((AdjustmentDetailsQ.AdjustmentHeadID)=[Forms]![AdjustmentHead]![AdjustmentHeadID]) AND ((AdjustmentDetailsQ.ActQOnH) Is Not Null));"
DoCmd.RunSQL strSql

strSql = "UPDATE Orders SET Orders.Adj = -1"
strSql = strSql & " WHERE (((Orders.OrderID) Like 'adj*'));"
DoCmd.RunSQL strSql


strSql = "UPDATE Transactions SET Transactions.AdjTrans = -1"
strSql = strSql & " WHERE (((Transactions.TransactionNo) Like '*Adj*'));"
DoCmd.RunSQL strSql


'Closing Form

DoCmd.Close
Posted
Comments
Richard Deeming 8-Jun-15 6:47am    
Your code is vulnerable to SQL Injection[^].

NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.
MOUTAZ877 8-Jun-15 7:03am    
I did not get your point , it was running fines then it stopped

what shall i do to fix it ?
[no name] 8-Jun-15 7:06am    
"what shall i do to fix it ?", use proper parameterized queries just like Richard said.

1 solution

It looks like you might need quotes around some of your values, however, do not try to fix the code you have. Please change the code you have to use parameters so that you are doing it correctly.

For example:
C#
String sql = "UPDATE table1 SET field1=@field1, field2=@field2...
...
cmd.Parameters.AddWithValue("@field1", txtField1.Text);
cmd.Parameters.AddWithValue("@field2", txtField2.Text);
...


Once you have done it this way your syntax issue will be gone too.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900