Updating multiple fields from VBA

roland_access

Registered User.
Local time
Today, 10:09
Joined
Feb 13, 2002
Messages
35
I have a form linked to a table containing stock information. When someone changes the stock amount, i want what stock item it was, when (time and date) it was changed and what it was changed to stored in another table.

I got the following code to do this on an after update


set MyRecords = currentdb.openrecordset("Log", dbopendynaset)

With MyRecords
.addnew
!StockID = Me.StockIDCode
.update
end with
MyRecords.close

Now this works fine for one field, but i then need to enter the current date and time in the next field and what was changed in the next to complete the record.

I tried this using .Edit instead of .addnew and it just edited the top most record, not the new one. Any ideas please?
 
You can add to every field within the table with the code you have there. All it needs is en extra line for each field i.e

set MyRecords = currentdb.openrecordset("Log", dbopendynaset)

With MyRecords
.addnew
!StockID = Me.StockIDCode
!TimeOfChange = Time
!DateOfChange = Date
etc...
.update
end with
MyRecords.close
 
Silly me, thank you!
 

Users who are viewing this thread

Back
Top Bottom