>Anybody know how to import XLS files to Access2000 by using VB6's code?
I have this code that I never tried but that seems good:
How can i trasnfered Excel data into access database using VB.(but not
opening access in another window)
This code will create a new table in an access database containing the
contents of an excel spreadsheet. You must have a reference to ADO 2.1 in
your project.
Dim cnnAccess As New ADODB.Connection
Dim rstXfr As New ADODB.Recordset
cnnAccess.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=access.mdb;Persist Security Info=False"
cnnAccess.Open
rstXfr.Open "SELECT Table.* INTO Table FROM Table IN 'table.xls'
EXCEL
5.0;'", cnnAccess
cnnAccess.Close
Set rstXfr = Nothing
Set cnnAccess = Nothing
Open your Access database
Dim db as Database
Dim td As TableDef
db = dbengine.workspaces(0).OpenDatabase(
)
The easiest way now (if you have structured data in your excel table) is
to
connect the excel sheet to your database and then use it as a "normal"
table.
Set td = db.CreateTableDef("MyNewTable")
td.Connect = "Excel 5.0;HDR=YES;IMEX=2;DATABASE=C:\TEMP\YourExcel.xls"
td.SourceTableName = "Tabelle1$"
db.TableDefs.Append td
db.TableDefs.Refresh
Now you can you the ExcelSheet as a table in your database and do all the
oparations you want to do.
To "understand" the connectstring just use your access, link an excel
sheet
and have a look (debugger) at the values of CurrentDb.Connect and
CurrentDb.SourceTableName
Éric Moreau, MCPD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Moer inc.
http://www.emoreau.com