Function fncImportFiles(strName As String)
Dim rstTemp As New ADODB.Recordset
Dim rstWrite As New ADODB.Recordset
Dim conTemp As New ADODB.Connection
Dim iCtr As Integer
'Open recordset on table in database
'How are we going to know what the table is called?
'Ive assumed here that the spreadsheet has the same name as the table
rstWrite.CursorType = adOpenStatic
rstWrite.CursorLocation = adUseServer
rstWrite.ActiveConnection = CurrentProject.Connection
'Assuming the table is the same name as the spreadsheet, we want to remove the .xls
'from SpreadsheetName.xls to use as the table
rstWrite.Open "SELECT * FROM & " & Left(strName, Len(strName) - 4)
'open connection to spreadsheet
conTemp.Open "DRIVER=Microsoft Excel Driver (*.xls);DBQ=C:\Temp\Files\" & strName
'open recordset on spreadsheet
rstTemp.CursorType = adOpenStatic
rstTemp.CursorLocation = adUseServer
rstTemp.ActiveConnection = conTemp
'NB: This assumes that the data is on the first sheet - and you must have the $ after the name - might
'require some playing around with
rstTemp.Open "SELECT * FROM [Sheet1$]"
Do Until rstTemp.EOF
rstWrite.AddNew
For iCtr = 0 To rstWrite.Fields.Count - 1
'Wang the data into the table opened up by rstWrite
rstWrite.Fields(iCtr) = rstTemp.Fields(iCtr)
Next
rstWrite.Update
rstTemp.MoveNext
Loop
'clean up
rstTemp.Close
rstWrite.Close
conTemp.Close
End Function