Hi FireGeek,
What you do is to continue importing the sheets directly into the front
end. The trick is to note the new table name then do an Insert Into
query to get the data into the back end. A slightly more sophisticated
technique would be to just import the data directly into the backend
from Excel, but that would require a rewrite of your code. Without
having to rewrite your current code you just copy the data as you have
been. Then in the same command button you add this:
Private Sub Command1_Click()
Import data from excel...
'--get new table name from the import action above - then
DoCmd.RunSql "Insert Into backendTbl select * from " & newTblName
End Sub
The more sophisticated way uses Excel automation - make a reference to
the Excel Object Library from a code module - goto Tools/References and
select Microsoft Excel 11.0 Object Library (or whatever your version of
Excel - if you have more than one version of Excel running on your
machine - pick the highest version). Now you can write code like this:
Sub ImportExcelData()
Dim xl As Excel.Application, wkbk As Excel Workbook, sht As
Excel.WorkSheet, rng As Excel.Range
Dim DB AS DAO.Database, RS As DAO.Recordset
Dim i As Integer, j As Integer
Set xl = CreateObject("Excel.Application")
Set wkbk = xl.Workbooks.Open("C:\dir1\yourWkbk.xls")
Set sht = wkbk.Sheets("Sheet1")
set rng = sht.UsedRange.
Set DB = CurrentDB
Set RS = DB.OpenRecordset("backendTbl")
For i = 1 to rng.Rows.Count
For j = 1 to rng.Columns.Count
RS(i - 1) = rng(i, j)
Next
Next
RS.Close
End Sub
This example uses the Excel Range object to retrieve all the data from
Sheet1 that is contained in the "UsedRange". The "UsedRange" is an
Excel object that consists of all the cells on a sheet which have been
filled with data. Note: when using "UsedRange" if data gets deleted
from rows in the lower part of the sheet, those rows still count as a
used range. So UsedRange only works reliably with New Sheets or sheets
where the data will never change once you have used the UsedRange
object.
Rich
*** Sent via Developersdex
http://www.developersdex.com ***