Solved

Access Import From Excel Error

Posted on 2011-03-21
5
590 Views
Last Modified: 2012-05-11
Hi,
I am importing information from Excel to Access using the DoCmd.TransferSpreadsheet command from with VBA.  The Excel information is being downloaded from SAP and has an issue that Access does not like when importing.  On certain fields like vendor number, that is all numbers, sometimes shows up in Excel as a numeric value, but other times shows up with an error.  The error being "number Stored as Text".  Please see image.  When Access imports this column, it will import the cells with no errors, but will not import the cells with the "number Stored as Text" error.  Access gives the import error message of "Type Conversion Failure" regardless if the field in the Access table is setup as text or as a number.
Please Help, all help will be greatly appreciated.
Thanks!
Gary Excel Error Screen Shot
0
Comment
Question by:tgtg7
5 Comments
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 35183329
When I import from Excel, I almost always setup a dummy table where I do the imports to.  In this table, every field is a text field.  I then run check for invalid values and run another query that inserts the values from this temp field into the actual destination table, doing explicit type conversions as necessary.
0
 
LVL 18

Expert Comment

by:Richard Daneke
ID: 35184423
You can edit your import query to convert the field date as well.   A CLng, Ccur, CStr, CVar, or even NZ([field],0) functions can help.  This example looks like a CLng([ExcelFieldName])  would do the trick.  

SQL example    CLng([ExcelFieldName])  as lngExcelFieldName

QBE Field Name example  lngExcelFieldName : CLng([ExcelFieldName])
0
 
LVL 3

Expert Comment

by:babesia
ID: 35184445
Above will work or you can DO a check on the fly.
IF Cell isnumber then

copy cell

else  IF cstr(Cell) is number then

copy cstr(cell)

else
error
end if


0
 

Accepted Solution

by:
tgtg7 earned 0 total points
ID: 35190521
I have spent a lot of time trying different things.  It appears this whole problem relates to the SAP generated Excel files.  If I create other other Excel files from scratch with the same issues, Access has not problem importing the information.   To solve the issue, I ran this vba code over the Excel data from SAP that is to be imported(see code).

I would like to be able to run this code from within Access, meaning the vba code would be housed within Access for a paricual range for a particular workbook.  Any help on this?

Thanks for the help!
Gary
Sub MassageImportData()
 
    Do While IsEmpty(ActiveCell.Value) = False
        If IsEmpty(ActiveCell.Value) = False Then
            ActiveCell.Columns("A:A").EntireColumn.Select
            
            Selection.TextToColumns Destination:=ActiveCell, DataType:=xlDelimited, _
                TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
                Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
                :=Array(1, 1), TrailingMinusNumbers:=True
            ActiveCell.Offset(0, 1).Activate
        Else
            ActiveCell.Offset(0, 1).Activate
        End If
    Loop
    
End Sub

Open in new window

0
 

Author Closing Comment

by:tgtg7
ID: 35292589
After much trial and error, the above code solved the problem.
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question