How to use VBA to add new record in MS Access?

The solution for “How to use VBA to add new record in MS Access?” can be found here. The following code will assist you in solving the problem.

Private Sub btnAddRecord_Click()
Dim tblCustomers As DAO.Recordset

Set tblCustomers = CurrentDb.OpenRecordset(“SELECT * FROM [tblCustomers]”)
tblCustomers.AddNew
tblCustomers![Customer_ID] = Me.txtCustomerID.Value
tblCustomers![CustomerName] = Me.txtCustomerName.Value
tblCustomers![CustomerAddressLine1] = Me.txtCustomerAddressLine1.Value
tblCustomers![City] = Me.txtCity.Value
tblCustomers![Zip] = Me.txtZip.Value
tblCustomers.Update
tblCustomers.Close
Set tblCustomers = Nothing
DoCmd.Close
End Sub

Thank you for using DeclareCode; We hope you were able to resolve the issue.

More questions on [categories-list]

Similar Posts