Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

open excel file for data import into an access database 1

Status
Not open for further replies.

ef61778

IS-IT--Management
Sep 23, 2003
14
US
How do I open a specific excel file for data import into an access database using Visual Basic
 
I think this piece of code will give you an idea to read from excel into access table....

Dim a As Object
Dim w As Object
Dim WSN As Object
dim filename as string
'define all the fields accordingly

filename = "c:\xxxxxx.xls"
Set a = CreateObject("Excel.Application")
Set w = a.Workbooks.Add(filename)
Set WSN = w.Worksheets(1)
WSN.Activate

set rs = db.openrecordset("select * from accesstable")
for x = 1 to lastlineof the worksheet
rs.addnew
rs.field1 = activesheet.cells(x,1)
rs.field2 = activesheet.cells(x,2)
........ all fields
next x
hope it helps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top