Using recordset to add fields to a different table

  • Thread starter Thread starter Allie
  • Start date Start date
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
 
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

=========================================
 
Back
Top