次の例では、New Customers テーブルのすべてのレコードを選択し、Customers テーブルに追加します。個々の列を指定しない場合は、SELECT でのテーブルの列名と INSERT INTO でのテーブルの列名とが一致している必要があります。
Sub InsertIntoX1()
Dim dbs As Database
'
この下の行を、使用しているコンピュータ上の
' Northwind
のパスに変更してください。
Set dbs = OpenDatabase("Northwind.mdb")
' New Customers
テーブルのすべてのレコードを選択し、
' Customers
テーブルに追加します。
dbs.Execute " INSERT INTO Customers " _
& "SELECT * " _
& "FROM [New Customers];"
dbs.Close
End Sub
次の例では、Employees テーブルに新しいレコードを作成します。
Sub InsertIntoX2()
Dim dbs As Database
'
この下の行を、使用しているコンピュータ上の
' Northwind
のパスに変更してください。
Set dbs = OpenDatabase("Northwind.mdb")
' Employees
テーブルに新しいレコードを作成します。
'
氏名は "Harry"
、姓は "Washington"
、
'
役職は "Trainee"
です。
dbs.Execute " INSERT INTO Employees " _
& "(FirstName,LastName, Title) VALUES " _
& "('Harry', 'Washington', 'Trainee');"
dbs.Close
End Sub