PC Review


Reply
Thread Tools Rate Thread

How do I correct "Type conversion Failure" in Access 2007

 
 
BigK
Guest
Posts: n/a
 
      7th Sep 2009
Importing database from Excel 2007 and get "Type Conversion Failure" in a
couple columns containg numbers. Have tried changing the fields data type to
text, etc. No luck.
Help?
 
Reply With Quote
 
 
 
 
Piet Linden
Guest
Posts: n/a
 
      7th Sep 2009
On Sep 7, 3:02*pm, BigK <B...@discussions.microsoft.com> wrote:
> Importing database from Excel 2007 and get "Type Conversion Failure" in a
> couple columns containg numbers. Have tried changing the fields data typeto
> text, etc. No luck.
> Help?


Try creating a table by linking to the Excel file and creating an
empty table. Then fix the columns that are not working, then run the
append.
 
Reply With Quote
 
New Member
Join Date: Nov 2009
Posts: 2
 
      20th Apr 2012
Access looks at the first row(s) to determine what the rest of the column contains. If it sees all numbers, it will import it as a number. If any subsequent rows are text, the import will fail on those records. You can insert a dummy row in excel under the header column. If a column should be text, have the cell in the second row be text. Once imported, delete the dummy row from your table.

I use the vb code in Access to open the workbook, insert a row and set text or numbers in the second row.

Code:
Private Sub InsertDummy()
'--------------------------------------------------------------------------------
'When Access imports a spreadsheet, it looks at the values in the first data row
'to determine the format of the rest of the rows.
'In my case I need columns A and B to be text and columns C and D to be numeric.
'This code opens the Excel spreadsheet to be imported into Access and inserts a 
'row below the header row.
'It then inserts AAA in cell A2, BBB in cell B2, 1 in cell C2 and 10 in cell D2
'When complete, the workbook is saved, closed and Excel exits
'--------------------------------------------------------------------------------
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Set xlApp = New Excel.Application                                        'Open Excel workbook
xlApp.Visible = True
Set wbExcel = xlApp.Workbooks.Add
Set xlBook = xlApp.Workbooks.Open("full path to your spreadsheet")        'ie "C:\My Documents\Data To Import.xlsx"
xlApp.DisplayAlerts = False
Workbooks("Data To Import.xlsx").Activate
        Sheet1.Activate
        Sheets("Sheet1").Activate                                        'Sheet1 should be the actual name of your work sheet
        Range("a2").Select
        ActiveCell.EntireRow.Insert                                        'Insert a row below the header
        Cells(2, 1).Value = "aaa"                                          'begin adding text and numbers as required
        Cells(2, 2).Value = "bbb"
        Cells(2, 3).Value = 1
        Cells(2, 4).Value = 10
xlBook.Save
Workbooks("Data To Import.xlsx").Close
xlApp.Quit
xlApp.DisplayAlerts = True
Set xlBook = Nothing
Set xlApp = Nothing
End Sub
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Access 2007 "attachment" "Data Type" not an option Shane Microsoft Access Database Table Design 2 11th Sep 2009 07:43 PM
why "Type Conversion Failure" import EXCEL into ACESS TEXT field Joe Microsoft Access External Data 1 25th Aug 2009 05:34 PM
Import from Text File - "Type Conversion Failure" =?Utf-8?B?ZGNvenpp?= Microsoft Access External Data 2 20th Mar 2006 08:32 PM
"Type Conversion Failure" errors Paddy Microsoft Access External Data 1 20th Jul 2004 01:20 PM
Emulate SQL Type Conversion "ALTER TABLE - CHANGE" in ACCESS 97 TDN Microsoft Access Queries 3 13th Apr 2004 05:47 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:42 AM.