How to programmatically add a record in a bound subform?

T

Tom Lewis

I have a textbox control called "Name" in my main form
(single form view), and a linked subform (datasheet view),
bound to a table "NameHistory" that lists all the "Names"
that have been entered or changed in the main form.

I want to automatically insert a record in
the "NameHistory" table when the value in the "Name"
control is modified. Is it possible to do this directly
using methods for Access objects, or is it necessary to
use DAO/ADO recordsets and perform the insert operation
behind the scenes?

Thanks for any help,

Tom
 
A

Allen Browne

Tom, you need to Execute an Append Query statement to add the history entry
to the subform.

Use the AfterUpdate event procedure of the form to append the record.
Trouble is that the OldValue of the name is no longer available at this
time. You will therefore need to store the OldValue into a module-level
variable in the BeforeUpdate of the form, and use it in Form_AfterUpdate.

If the field/text box really is called "Name", you will probably run into
problems with this code. Most objects (including forms) have a Name
property, so you have an ambiguity when you attempt to refer to the Name
field/control on the form.
 

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