Article ID: 145826
Article Last Modified on 10/11/2006
CompanyName Phone
United Shipping (111)222-3333
Carriers Inc. (999)888-7777
Sub AppendTable()
Dim db As database
Dim rs As recordset
Dim XLTable As TableDef
Dim strSQL As String
'Open the Microsoft Access database.
Set db = OpenDatabase("C:\MSOffice\Access\Samples\Northwind.mdb")
'Attach the Microsoft Excel 5.0 table "MyTable" from the file
'Book1.xls to the Microsoft Access database.
Set XLTable = db.CreateTableDef("Temp")
'In Microsoft Excel 97, use
'
' XLTable.Connect = "Excel 8.0;DATABASE=...
'
'The rest of the line is the same.
'
XLTable.Connect = "Excel 5.0;DATABASE=C:\My Documents\Book1.xls"
XLTable.SourceTableName = "MyTable"
db.TableDefs.Append XLTable
'Run the append query that adds all of the records from MyTable
'to the Shippers table.
strSQL = "Insert into Shippers Select * from Temp"
'Execute the SQL statement.
db.Execute strSQL
'Remove the attached table because it's no longer needed.
db.TableDefs.Delete "Temp"
db.Close
End Sub
OpenRecordset, Execute, CreateTableDef, Append
Additional query words: 8.00 97 XL97 XL
Keywords: kbdtacode kbhowto kbprogramming kbualink97 KB145826