Discussion Locked

ADODC.Recordset.AddNew syntax

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

By the looks of it, adding a new record in ADO is a bit different to DAO.

Can anyone expand on the object browsers syntax of AddNew([FieldList],[Values])

I've got textboxes linked to the ADODC, and I want to add them to my databse.

I'm using VB6.

Thanks

5 replies

by sergey kovzik

DAO.Recordset.AddNew
This sets fields to default values. Then you need to assign values and use Update method

ADODC.RecordSet.AddNew([FieldList],[Values])
Here if you don't use FieldList and Values you can do as above, if you provide them - youdon't need to use Update. There is also BatchMode. In it you do as above but after all you have to call UpdateBatch to save entire transaction.

Sincerely, Sergey
Brainbench MVP for Win98 Administration

by craig shepherd

Thanks, but I already had most of that in my question. I wanted to know what to put in FieldList and Values.

by andrew

The two parms for AddNew are Variant arrays.
You can use the Array function to create a variant array from comma delimited list of elements.

If you only have one field in the Recordset, you can use syntax like:

Rs.AddNew("Field1", "Value1")
If you have multiple fields, the following syntax is pretty concise:

Rs.AddNew(Array("Field1","Field2"), Array("Value1","Value2"))

Hope this helps.

This discussion is closed to new replies.