Question : Access 2003: transfer spreadsheet is failing

Hi EE,

a) Would like to import an excel file to an Access table.
    (btw, this excel file is created by excuting an Oracle tool called Discoverer in a .bat file
      and feeding a parameter asking Discoverer to create an Excel file)

b) Below is a screen shot of the error
c) The VBA:
          1) opens the Excel file,
          2)  loops through the heading names to created a 'customized' table.
               While looping, the VBA establishes the data type of the field.
          3) At the end of the loop, the VBA creates 2 additional fields:
               autonumber
               yes/no  - then VBA converts the yes/no field to a check box property
          4) VBA saves excel file and closes excel
          5) VBA ** attempts ** to import the excel file to a temp table - it's failing
               The table has no key defined, so do not understand why failing.

           (btw, i've done steps 1-5 before with another project and it worked successfully,
               not sure why this excel file is having trouble)

Would it be possible for you to take a look at the test mdb below, pls?

c) Below is a zip file with:
     1) test mdb
     2) excel file - with just header row and 1 data row
           (it's very strange - when i manually import this test file using get file/import, the file import
            successfully, but with 2 extra blank rows. When i import the prod file of 80 records,
            manually, the import works, as well ** without ** extra blank rows)

d) regarding the test mdb:
     a) just contains the form with the problem
     b) for the screen, please choose 200930  then 'APR'

tx for your ideas and help, sandra

Answer : Access 2003: transfer spreadsheet is failing

try importing the excel file to a non existing table (strTable="TempTable")
and append the data to the destination table after importing
then delete the "temptable"
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
Public Sub I005_ImportExcelToAccess(strExcelFile As String, _
                                    strTableName As String)

Dim strTable
strTable = "TempTable"
Call q715_DeleteFrom_Table(strTableName)

DoCmd.TransferSpreadsheet _
      TransferType:=acImport, _
      TableName:=strTable, _
      FileName:=strExcelFile, _
      HasFieldNames:=True
'append the imported records
CurrentDb.Execute "insert into Tbl_Temp select * from [" & strTable & "]"
'drop the tempTable
CurrentDb.Execute "drop table [" & strTable & "]"

End Sub
Random Solutions  
 
programming4us programming4us