Update one table when another changes

cgclower

New Member
Joined
Feb 28, 2010
Messages
40
Hello!
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
I have a database with two tables (well actually a lot more, but only two that matter for this question). I am trying, via VBA, to update one of the tables every time a record is added to the other table. Right now, I am planning on using this command:
<o:p></o:p>
Code:
Sub Form_AfterInsert()
<o:p></o:p>
DoCmd.RunSQL "INSERT INTO SecondTable VALUES([some value from FirstTable], [some other value from FirstTable])"
<o:p></o:p>
End Sub
<o:p></o:p>
My question is how do I get the values from the first table after the record was inserted? I was hoping for some sort of LastRecordInserted function that would have that data, but I am not finding anything like that.
<o:p></o:p>
Thoughts? Advice? Taunts and laughter? :)
<o:p></o:p>
Thanks for the help!
<o:p></o:p>
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
I guess my question would be to find out if this is really necessary. Most of the time, if a database is designed well and normalized, this sort of thing usually isn't necessary (just like any calculation that can be done in a query should not be stored in a query).

So, can you explain exactly what you are trying to do, and why it needs to happen like this?
 
Upvote 0
I have a table with a bunch of account information in it. When someone adds or deletes an account from that table, I want to show the account number and "Created" or "Deleted" somewhere, along with the date and user who deleted it. I guess adding an account could be tracked in the same table, but I can't keep track of the deletions there. Can I?
 
Upvote 0
One idea is to change how it works. Instead of actually deleting the data, perhaps you can add a checkbox that they would check to "delete" the data (but it really wouldn't delete it, just hide it from view). Then you could have VBA code that is triggered when this check box is selected to update your datestamp flag.

I don't know how your database is designed, but in this type of scenario, you would want the database to be a form-driven database, which means that you direct all activity through forms so users don't go into the tables directly. That way you can control how all this works, especially with updating date stamps.
 
Upvote 0

Forum statistics

Threads
1,224,570
Messages
6,179,608
Members
452,930
Latest member
racefanjtd

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top