1

I have one table called: Transaction. This table has the following fields: (ID,ProductName,Amount,Date) placed in an excel sheet that is connected with MS Access database. ID is the only unique field. Sometimes, my user submits a transaction that has let's say 5 records. Then, they want to modify the submitted data in case if they entered incorrect amount and they want to correct it. I want to write a code in VBA that will do the update. my current query is:

Update table Transaction(ProductName,Amount) set ProductName=@Product,Amount=@Amount)
where Date=@date;

This query does not work fine because obviously it replaces all the records data with the data of the last resubmitted record because my condition is weak. My difficulty is that I can't find a good condition in the where clause that will do the update a record by record accordingly. Please help,

6
  • You will need to gain access to the unique ID field and use that in your where clause for the updates. Commented Sep 20, 2010 at 16:10
  • Is ID different for each record? Could you add a where criteria that lists all the IDs? Commented Sep 20, 2010 at 16:12
  • yes, the ID is an identifier (autonumber). Commented Sep 20, 2010 at 16:22
  • @Doug, can you please clarify how that will be in SQL? Commented Sep 20, 2010 at 16:25
  • Update table Transaction(ProductName,Amount) set ProductName=@Product,Amount=@Amount) where ID = "id of record you want to update" Commented Sep 20, 2010 at 16:38

1 Answer 1

1

You will need to use the unique id of the record, in your case the ID field to guarantee you are updating the correct record.

Something like the following:

Update table Transaction(ProductName,Amount) set ProductName=@Product,Amount=@Amount) where ID = "id of record you want to update"

Enjoy!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.