April 2006
Beginner
1114 pages
98h 16m
English
recordset.AddNew([FieldList], [Values])
Creates a new record.
|
Argument |
Description |
|---|---|
|
|
A single field name or an array of names or ordinal numbers specifying the fields in the new record |
|
|
A single field value or an array of values for the fields |
The following code adds a new record to the Employees table in the Northwind Traders sample database using cell values on the current worksheet:
Dim cnn As ADODB.Connection
Dim cmd As ADODB.Command
Dim rs As ADODB.Recordset
Dim strDbPath As String
Dim strConnect As String
Set cnn = New ADODB.Connection
Set cmd = New ADODB.Command
Set rs = New ADODB.Recordset
strDbPath = "C:\Program Files\Microsoft Office\OFFICE11\SAMPLES\Northwind.mdb"
cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=" & strDbPath
cnn.Open
rs.Open "Employees", cnn, adOpenDynamic, adLockOptimistic, adCmdTable
rs.AddNew
rs!LastName = ActiveSheet.Range("B4")
rs!FirstName = ActiveSheet.Range("C4")
rs.Update
rs.Close
cnn.Close
Set rs = Nothing
Set cnn = NothingRead now
Unlock full access