Lasers07
asked on
update SQL Query in VBA Using Variables
I am trying to use an update query but cannot get the syntax correct. Please advise. This is obviously my hardest thing to grasp (SQL Query syntax with variables).
For Each varItm In Me.lstVendorPartsList.Item sSelected
varPartID = Me.lstVendorPartsList.Item Data(varIt m)
DoCmd.SetWarnings False
Dim sqlStr As String
sqlStr = "UPDATE " & varTmpTableName1 & " SET " & varTmpTableName1 & ".[qtytopurchase] = " & varUpdateQty _
& " WHERE (((" & varTmpTableName1 & ".PartID)= " & varPartID
'MsgBox sqlStr
DoCmd.RunSQL sqlStr
DoCmd.SetWarnings True
Next
For Each varItm In Me.lstVendorPartsList.Item
varPartID = Me.lstVendorPartsList.Item
DoCmd.SetWarnings False
Dim sqlStr As String
sqlStr = "UPDATE " & varTmpTableName1 & " SET " & varTmpTableName1 & ".[qtytopurchase] = " & varUpdateQty _
& " WHERE (((" & varTmpTableName1 & ".PartID)= " & varPartID
'MsgBox sqlStr
DoCmd.RunSQL sqlStr
DoCmd.SetWarnings True
Next
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Cap! I think u are on a roll getting points off my syntax questions! LOL.
You need not be so explicit in naming the table every time you mention a field in the table.
sqlStr = "UPDATE " & varTmpTableName1 & " SET [qtytopurchase] = " & varUpdateQty _
& " WHERE PartID)= " & varPartID