Solved

Access Import From Excel Error

Posted on 2011-03-21
5
595 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 19

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

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

734 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