Results 1 to 8 of 8
  1. #1
    gammaman is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    56

    transferspreedsheet not importing all rows.


    I have an excel file with about 4800 rows. I am using transferspreedsheet to import the rows into an access table, however only 14 out of the 4800 rows are being imported b/c all of the other rows in the excel file contain some blank cells which is causing them to error and not get imported. How can I import all the rows and just have blank data inserted into the database for the rows in the excel file that have blanks. Below is my code.

    Code:
    Public Sub Import()
    
    
    'DoCmd.SetWarnings (WarningsOff)
    
    
    
    
    Set db = CurrentDb()    'Establish a Connection to the Current Database
    
    
    On Error Resume Next
    DoCmd.RunSQL ("DROP TABLE 041913_ARMS_Manual_Review_2")       'Drop Table if exists
    DoCmd.RunSQL ("CREATE TABLE [041913_ARMS_Manual_Review_2]")   'Create the loading table
    
    
    Set tb1 = db.TableDefs("041913_ARMS_Manual_Review_2")         'Create a table definition to add fields to loading table
    Set fd = Application.FileDialog(msoFileDialogFilePicker)      'Open file chooser to select file to load into loading table
    
    
    counter = 0    'Set column counter to zero.
    
    
    With fd
    .Show
    For Each vrtSelected In .SelectedItems
    
    
       Set xlapp = CreateObject("Excel.application")
       Set xlWrkBk = GetObject(vrtSelected)
       Set xlsht = xlWrkBk.Worksheets(1)
    
    
       'Loop First Row in Excel File which contains header column names
    
    
       strcolumns = Array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "AA", "AB", "AC", "AD", "AE", "AF", "AG", "AH", "AI", "AJ", "AK", "AL", "AM", "AN", "AO", "AP", "AQ", "AR", "AS", "AT", "AU", "AV", "AW", "AX", "AY", "AZ", "BA", "BB", "BC", "BD", "BE", "BF", "BG", "BH")
    
    
    
    
       For Each strColumn In strcolumns
    
    
          counter = counter + 1                         'increase the counter to determine the number of columns
          Set columnName = xlsht.Cells(1, strColumn)
    
    
                Set FieldName = tb1.CreateField(columnName, dbText, 200)     'insert text type fields into table def
                tb1.Fields.Append FieldName 
       Next strColumn
    
    
       'transfers data from excel file and imports it into access table
       DoCmd.TransferSpreadsheet acImportDelim, , TableName:="041913_ARMS_Manual_Review_2", FileName:=vrtSelected, HasFieldNames:=True
    Next vrtSelected
    End With

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,441
    Does your target table have a primary key involving any of those null fields? excel 'null' fields are, I think stored as a blank text field in other words a string with 0 length "". have you tried converting those to null values for any number fields?

  3. #3
    gammaman is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    56
    No, the target table does not have any keys. It simply stores the data being imported. The macro first reads the excel sheet and creates the table fields (all "text" datatype), using row A1 of the excel spreadsheet. I then simply use transferspreedsheet to read in the data from the sheet. I don't understand though, since all of my fields are "text" (all of the cells on the spreadsheet are also all "text"), it should just insert the "blank" cells into the access table.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Try changing acImportDelim to just acImport.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    gammaman is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    56
    Still does not work. Attached is the error message.

    Click image for larger version. 

Name:	accesserror.png 
Views:	17 
Size:	37.2 KB 
ID:	12847

  6. #6
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,441
    have you got a sample of the database and the file you can post?

    (something 2007 or prior if you can)

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    I did a test and cannot replicate issue. If you want to provide files as suggested by rpeare, follow instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    vincent-leeway is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    May 2013
    Posts
    36
    I wonder if you tried out steps in this link, http://support.microsoft.com/kb/141228

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Importing Excel File - Getting 7 extra blank rows each import
    By eking002 in forum Import/Export Data
    Replies: 4
    Last Post: 06-13-2013, 09:15 AM
  2. Importing specific rows and columns
    By asmores in forum Import/Export Data
    Replies: 2
    Last Post: 03-26-2013, 12:31 PM
  3. Sum Of Rows
    By Arsalan in forum Database Design
    Replies: 1
    Last Post: 01-15-2013, 07:22 AM
  4. Replies: 0
    Last Post: 02-09-2012, 05:43 PM
  5. Replies: 2
    Last Post: 08-28-2011, 06:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums