Hey Guy, I am Trying to Update Multiple Field in a Table where the IDs are equal to the "ID" in the Combo Box. Is there a better way to do this? Use a Recordset?
Here's what I have?
Private Sub BtnSaveProcessRefund_Click()
DoCmd.RunSQL "UPDATE ExpenseT SET ExpenseT.ExpenseStatusID = '515' WHERE ExpenseT.ExpenseID=" & CboExpenseNumber DoCmd.RunSQL "UPDATE ExpenseT SET ExpenseT.Subtotal = 0 WHERE ExpenseT.ExpenseID=" & CboExpenseNumber DoCmd.RunSQL "UPDATE ExpenseT SET ExpenseT.AmountPaid = 0 WHERE ExpenseT.ExpenseID=" & CboExpenseNumber DoCmd.RunSQL "UPDATE ExpenseT SET ExpenseT.SalesTaxPercentage = 0 WHERE ExpenseT.ExpenseID=" & CboExpenseNumber DoCmd.RunSQL "UPDATE ExpenseT SET ExpenseT.DiscountPercentage = 0 WHERE ExpenseT.ExpenseID=" & CboExpenseNumber DoCmd.Save DoCmd.Close acForm, Me.Name, acSaveYes DoCmd.OpenForm "ExpenseDashboardF", acNormal
End Sub
Kevin Yip
@Reply 3 years ago
If the WHERE condition is the same, you can combine all updates into one SQL statement:
Kevin is correct. Plus, since you only have one table in your statement, you don't need to specify the table name. See my Access SQL Seminar, Part 2 for complete details.
James HopkinsOP
@Reply 3 years ago
Oh ok, thanks Kevin, I thought I could do it like you showed.
Sorry, only students may add comments.
Click here for more
information on how you can set up an account.
If you are a Visitor, go ahead and post your reply as a
new comment, and we'll move it here for you
once it's approved. Be sure to use the same name and email address.
This thread is now CLOSED. If you wish to comment, start a NEW discussion in
Access TechHelp.