Storing Data

C

Carl Johnman

Can someone please tell me how to store text entered into
a field in a table into another table automatically. I
need the same value updated in both fields at the same
time.
 
B

Brendan Reynolds \(MVP\)

There is no way to do this when entering data directly into tables, unless
using a server database engine such as SQL Server that supports triggers. If
you're not using a server database engine that supports triggers, you will
need to ensure that data is always entered via forms, and add code to the
AfterInsert (if you just need to record records once, when they are first
added) or AfterUpdate (if you also need to record modifications to
previously entered records) event procedure of the form to add the data to
the other table. Here's an example that copies only new records ...

Private Sub Form_AfterUpdate()

CurrentProject.Connection.Execute _
"INSERT INTO Table2 (TwoText) VALUES ('" & _
Me!OneText & "')"

End Sub

.... where 'Table2' is the name of the second table, 'TwoText' is the name
of the field in the second table, and 'OneText' is the name of the control
on the form.
 
B

Brendan Reynolds \(MVP\)

Oops! The first line in the example code should have read 'Private Sub
Form_AfterInsert()' rather than 'Private Sub Form_AfterUpdate()'
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top