Click here to Skip to main content
15,894,405 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Updating AdjustmentHead & AdjustmentDetails
VB
'-------------------------------------------
    
    '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
    

Exit_CmdConfirm_Click:
    Exit Sub

Err_CmdConfirm_Click:
    MsgBox Err.Description
    Resume Exit_CmdConfirm_Click
    
End Sub
Posted
Updated 10-Nov-15 3:36am
v2
Comments
Richard Deeming 10-Nov-15 10:21am    
Your code is vulnerable to SQL Injection[^].

NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.
MOUTAZ877 10-Nov-15 10:51am    
Sorry I didnot understand i am not an expert with sql query can you explain to me in more details or write for me the correct code please please!
Richard Deeming 10-Nov-15 10:57am    
Any user of your system can type certain characters into your input controls which will change the way your query functions. They might accidentally type in a single quote and get a syntax error; or they might deliberately type in queries which will alter your database in unexpected ways.

The following links have a lot of good information about this security vulnerability:
Bobby Tables: A guide to preventing SQL Injection[^]
Everything you wanted to know about SQL injection (but were afraid to ask) | Troy Hunt[^]
How can I explain SQL injection without technical jargon? | Information Security Stack Exchange[^]
Query Parameterization Cheat Sheet | OWASP[^]
SQL injection attack mechanics | Pluralsight [^]
MOUTAZ877 10-Nov-15 11:05am    
Ok then how shall i right it ? I have no experience! Or give me an example
Richard Deeming 10-Nov-15 11:07am    
Wow, you read all of the information on those sites I linked to really fast. How did you manage to watch an hour-long video in under 8 minutes?
</SARCASM>

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