Solved

Access Import From Excel Error

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article will show you how to use shortcut menus in the Access run-time environment.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

863 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

23 Experts available now in Live!

Get 1:1 Help Now