Solved

Access Import From Excel Error

Posted on 2011-03-21
5
581 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Suggested Solutions

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
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 demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

759 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now