473,411 Members | 2,059 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

Type conversion issue

I am trying to import an Excel 2003 sheet into my Access 2003
database.

I get error message saying sheet could not be imported and it referred
me to an Import error table which showed type conversion error for one
of the columns. Please advise what that means and how I can make it
work?

Aug 1 '07 #1
6 2300
ARC
I've seen funny things happen with importing from Excel to Access.

I had a field I was importing, which was a part number field. My part number
field was a text field in my access table, however, the user that was having
trouble had only numbers in his import spreadsheet for the part number
column.

I think what was happening was Excel was considering the entire column to be
numeric, since the user only used numbers in this column. However, since my
import field in access was text, a data type conversion was resulting.

I ended up writing a "fixup" routine that would edit the import spreadsheet
directly and insert the literal character ( ' ) in front of the part number
for each row in the spreadsheet. This did the trick, but was a royal pain.

If you need a code sample, let me know.

Andy
<te****@hotmail.comwrote in message
news:11**********************@d55g2000hsg.googlegr oups.com...
>I am trying to import an Excel 2003 sheet into my Access 2003
database.

I get error message saying sheet could not be imported and it referred
me to an Import error table which showed type conversion error for one
of the columns. Please advise what that means and how I can make it
work?

Aug 1 '07 #2
On Jul 31, 9:37 pm, "tes...@hotmail.com" <tes...@hotmail.comwrote:
I am trying to import an Excel 2003 sheet into my Access 2003
database.

I get error message saying sheet could not be imported and it referred
me to an Import error table which showed type conversion error for one
of the columns. Please advise what that means and how I can make it
work?
Check out using an Import spec.

Aug 1 '07 #3
On Jul 31, 11:37 pm, "ARC" <a...@andyc.comwrote:
I've seen funny things happen with importing from Excel to Access.

I had a field I was importing, which was a part number field. My part number
field was a text field in my access table, however, the user that was having
trouble had only numbers in his import spreadsheet for the part number
column.

I think what was happening was Excel was considering the entire column to be
numeric, since the user only used numbers in this column. However, since my
import field in access was text, a data type conversion was resulting.

I ended up writing a "fixup" routine that would edit the import spreadsheet
directly and insert the literal character ( ' ) in front of the part number
for each row in the spreadsheet. This did the trick, but was a royal pain.

If you need a code sample, let me know.

Andy

<tes...@hotmail.comwrote in message

news:11**********************@d55g2000hsg.googlegr oups.com...
I am trying to import an Excel 2003 sheet into my Access 2003
database.
I get error message saying sheet could not be imported and it referred
me to an Import error table which showed type conversion error for one
of the columns. Please advise what that means and how I can make it
work?- Hide quoted text -

- Show quoted text -\

Thanks, I would like to see some sample code.
Aug 3 '07 #4
ARC
Here's the entire proc. I didn't have time to edit, but it is commented...
----------------------------------
Public Function FixPartsImportSheet() As Boolean
'This will add the ' character to the part number field.
'For some reason, even though the field in the table for importing parts is
text, and the
'spreadsheet column for part number is text, if there is a mixture of
straight numbers in the part number field
'and some cells with text, the ones with text do not get imported, and the
ones with numbers get transposed
'to scientific notation.
'The fix is to go through the import sheet and add the ' character
preceeding each part number.
'
On Error Resume Next
Dim mysheet As Object, xlApp As Object, sheetnm As String, cnt As Integer, j
As Integer, i As Integer, lastrow As Long, firstrow As Integer
cnt = 0
j = 2 'col 1=supplier part column is first column, col 2=description
column, col 8=manuf. num, col 9=UPC
i = 1
'
DoCmd.Hourglass -1
sheetnm = Forms!fImport.Form!txtFile
Set xlApp = CreateObject("Excel.Application")
Set mysheet = xlApp.workbooks.Open(sheetnm).sheets(1)
'1st, find last row of data, use description field as this is required
Do Until cnt 2 'break out if 2 blank cells in a row were detected
If Trim$(mysheet.cells(i, j).Value) <"Description" Then
If IsNull(mysheet.cells(i, j).Value) Then
cnt = cnt + 1
ElseIf Trim$(mysheet.cells(i, j).Value) = "" Then
cnt = cnt + 1
End If
Else
firstrow = i + 1
cnt = 3
End If
i = i + 1
'Call SetMessage("Getting last row number..." & i)
Loop
lastrow = i - 4
'2nd, find first row of part number column, and fix up with the ' symbol
j = 1
If Left(mysheet.cells(firstrow, j).Value, 1) <"'" Then
mysheet.cells(firstrow, j) = "'" & mysheet.cells(firstrow, j).Value
End If
'3rd, edit first data row for description, this is required field, so no
need to go through
j = 2
If Left(mysheet.cells(firstrow, j).Value, 1) <"'" Then
mysheet.cells(firstrow, j) = "'" & mysheet.cells(firstrow, j).Value
End If
'4th, edit first occurence in manuf num field
j = 8
If Left(mysheet.cells(firstrow, j).Value, 1) <"'" Then
mysheet.cells(firstrow, j) = "'" & mysheet.cells(firstrow, j).Value
End If
'last, edit the upc first occurence
j = 9
If Left(mysheet.cells(firstrow, j).Value, 1) <"'" Then
mysheet.cells(firstrow, j) = "'" & mysheet.cells(firstrow, j).Value
End If
''old routine below...i found that you don't have to put the ' in front of
each row, just the 1st row of data
'
'Do Until cnt 2 'break out if 2 blank cells in a row were detected
' If Trim$(mysheet.cells(i, j).Value) <"Supplier Part" Then
' If IsNull(mysheet.cells(i, j).Value) Then
' cnt = cnt + 1
' ElseIf Trim$(mysheet.cells(i, j).Value) = "" Then
' cnt = cnt + 1
' Else
' If Left(mysheet.cells(i, j).Value, 1) <"'" Then
' mysheet.cells(i, j) = "'" & mysheet.cells(i, j).Value
' End If
' End If
' End If
' i = i + 1
'Loop
'Save and exit out of Excel
'
'mysheet.Application.windows("Purchase.xls").Visib le = True
mysheet.Application.activeworkbook.Save
mysheet.Application.activeworkbook.Close
xlApp.Quit
Set mysheet = Nothing '
DoCmd.Hourglass 0
Exit Function
End Function
Aug 3 '07 #5
Thanks!!

Aug 4 '07 #6
ARC
You're welcome. Hope it helped, and wasn't major overkill.

Good luck!
<te****@hotmail.comwrote in message
news:11**********************@19g2000hsx.googlegro ups.com...
Thanks!!

Aug 4 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: balor | last post by:
I've got a problem involving casting operators using GCC 3.2 - hopefully someone here can help me out. I've written the following small program: class A { public: operator int() { return 2; }...
19
by: Randy Yates | last post by:
Consider the following code: #include "dsptypes.h" /* definitions */ #define VECTOR_LENGTH 64 /* local variables */
0
by: Oscar Thornell | last post by:
Hi, I have run into a VS.NET 2005 conversion issue. As a starter (before I go for production code) I tried to convert the well known Portal starter kit that can be downloaded from http://asp.net...
10
by: Arno R | last post by:
Hi all, I have a database that I need to use in different versions of Access. This is A97 in most places and A2k in a few other locations. (I develop in A97 and convert the db to A2k for these...
3
by: Ashish | last post by:
its on .net 2.0 I am calling a stored procedure which returns value SCOPE_INDENTITY() , when i try to convert the result from object to int, it throws a type conversion error... after some...
4
by: zaeminkr | last post by:
I got a good answer here I have still confusing part. I have two very simple classes class DRect { private : double x0, y0, x1, y1; public : DRect(double a, double b, double c, double d) :...
16
by: The Frog | last post by:
Hi Everyone, I have a small problem that doesnt seem to make any sense. I am using Access 97, and have a query that selects data from a text field, converts it to type Lng. This seems to work...
0
by: ssylee | last post by:
I know this is a c++ message board rather than a windows one, but my issue may be more related to type conversion (which is probably closer to c++). I'm trying to convert/cast for example,...
2
by: mkbrady | last post by:
I have a query that includes calculated fields that generate numeric results. I have wrapped conversion functions CLng() and CDdl() around the calculated fields to ensure the data types are...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.