Adding a New Record to a Table : Recordset Add Update Delete « Access « VBA / Excel / Access / Word






Adding a New Record to a Table

 
' Use the References dialog box to set up a reference to the Microsoft ActiveX Data Objects Library

Sub Add_Record()
   Dim conn As ADODB.Connection
   Dim myRecordset As ADODB.Recordset
   Dim strConn As String
   strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & CurrentProject.Path & "\mydb.mdb"

   Set myRecordset = New ADODB.Recordset
   With myRecordset
      .Open "Select * from Employees", _
         strConn, adOpenKeyset, adLockOptimistic
      .AddNew
      !LastName = "Marco"
      !FirstName = "Paulo"
      !City = "Boston"
      .MoveFirst
      .Close
   End With

   Set myRecordset = Nothing
   Set conn = Nothing
End Sub

 








Related examples in the same category

1.Add new a row to recordset
2.Adding a New Record to a Recordset
3.Use AddNew and specify the field information
4.Use AddNew method from Recordset and two arrays to add a new row
5.Modifying a Record
6.Performing Batch Updates
7.Delete row for a certain criteria
8.Deleting a Record
9.Call update method from Recordset
10.Call delete method in Recordset
11.Check the Recordset affected