Using recordset to add fields to a different table

A

Allie

How do I create a recordset to add specific fields from a
datasheet subform to a different table? The subform has
12 fields, I only need to added 5 of those fields to a
different table.

Thanks
 
X

xyonx

Assuming you know a little vba and that you're using DAO
on your references, on your form add a button with the
following code on the OnClick Event ...

=================================

'dimension variables to our database & recordset
Dim db As DAO.Database
Dim rs As DAO.Recordset

' set our variables
Set db = CurrentDb
' open recorset in dynaset mode
' replace "TableToUpdate" to the name of you table
Set rs = db.OpenRecordset("TableToUpdate",dbOpenDynaset)

' add a new record to the table
' reference the needed controls on your subform to add
' to chosen table
With rs
.AddNew
.Fields("TableField1") =
Me.YourSubForm.Your1stField
.Fields("TableField2") =
Me.YourSubForm.Your2ndField
' same thing for all of your necessary fields
.Update
.Close
End With

' release memory
Set rs = Nothing
Set db = Nothing

=========================================
 

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