Forum Moderators: open
Thanks folks!
I use code similar to the following to populate our Access database from Excel spreadsheets:
You'll need "Microsoft Excel 10.0 Object Library" in your Project > Preferences list
Set AppExcel = Excel.Application
Set AppExcel = CreateObject("Excel.Application")
' Location of your spreadsheet here
AppExcel.Workbooks.Open "C:\CCC\AUSTRALIA.xls"
intStarts = 1' set the first row
intEnds = 2' set the last row
For Down = intStarts To intEnds
strLocName = Trim(AppExcel.Cells(Down, 1))
strLocCode = Trim(AppExcel.Cells(Down, 2))
strLocAdd = Trim(AppExcel.Cells(Down, 3))
' update your database here
Next Down
Hope that helps (and works!).
Mick
Ross
The Excel object model has a built in method so you can avoid all that looping etc and do it in a single line of code.
objWorkBook.Cells(1, 1).CopyFromRecordset objRS