access vba ado add new record
' 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