Adding Records

To add a record using a recordset, the recordset type needs to be capable of updates. In DAO, you need to specify dbOpenDynaset for the Type, like this:

Set rec = db.OpenRecordset("tblMyTable", dbOpenDynaset) With rec


!MyField1 = "A" !MyField2 = "B" .Update End With

The .AddNew method of the recordset object instantiates the new record in the table, and if the table is in Access, also assigns a new AutoNumber key to the record if the table contains one. Don't forget the final .Update, because without it your record won't be added.

0 0

Post a comment