INSERT INTO Statement Example

This example selects all records in a hypothetical New Customers table and adds them to the Customers table. When individual columns are not designated, the SELECT table column names must match exactly those in the INSERT INTO table.

Sub InsertIntoX1()

   Dim dbs As Database

   ' Modify this line to include the path to Northwind
   ' on your computer.
   Set dbs = OpenDatabase("Northwind.mdb")
   
   ' Select all records in the New Customers table 
   ' and add them to the Customers table.
   dbs.Execute " INSERT INTO Customers " _
      & "SELECT * " _
      & "FROM [New Customers];"
      
   dbs.Close

End Sub

This example creates a new record in the Employees table.

Sub InsertIntoX2()

   Dim dbs As Database

   ' Modify this line to include the path to Northwind
   ' on your computer.
   Set dbs = OpenDatabase("Northwind.mdb")
   
   ' Create a new record in the Employees table. The 
   ' first name is Harry, the last name is Washington, 
   ' and the job title is Trainee.
   dbs.Execute " INSERT INTO Employees " _
      & "(FirstName,LastName, Title) VALUES " _
      & "('Harry', 'Washington', 'Trainee');"
      
   dbs.Close

End Sub