473,385 Members | 2,015 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,385 software developers and data experts.

Spreadsheet upload data convertion error

25
Hello everyone!

I got excel spreadsheet with lets say 50000 lines that I need to upload into access db. I created vba code to perform automated upload into specified table, however, as far as i understand, when access performs upload it takes first 25 rows of data from excel and determines the type of each field, then performs upload and then converts the data to match the one specified in the table. The problem I'm facing is that I have field "invoice number" that can be ranging from 8 to 11 digits. during upload time access recognizes the field as int, but when it comes accross 11 digit invoice number it blanks it out since its out of range for int's.
Is there a way to specify what data type to use before upload? (besides sorting data in excel)
Thanks a lot for any help.
Mar 26 '07 #1
11 1947
MMcCarthy
14,534 Expert Mod 8TB
Hello everyone!

I got excel spreadsheet with lets say 50000 lines that I need to upload into access db. I created vba code to perform automated upload into specified table, however, as far as i understand, when access performs upload it takes first 25 rows of data from excel and determines the type of each field, then performs upload and then converts the data to match the one specified in the table. The problem I'm facing is that I have field "invoice number" that can be ranging from 8 to 11 digits. during upload time access recognizes the field as int, but when it comes accross 11 digit invoice number it blanks it out since its out of range for int's.
Is there a way to specify what data type to use before upload? (besides sorting data in excel)
Thanks a lot for any help.
You have two options.
  1. Create the table first and upload the data into an existing table.
  2. Change the excel file to a csv file and create an import specification on how you want the data imported.
Mary
Mar 26 '07 #2
is49460
25
I'm trying to pursue the first suggested solution but some values are still getting lost during the conversion. for example:
excel file:
invoice number
1234
1235
1236
...

line 250: 1234df6

well, access drops line 250 because based on first 25 records it determined the field to be an integer, even tho I specify it as text in the destanation table... so it takes it as an integer uploads it and then converts in to text as specified in the table and that the problem I'm trying to work around.
second option is not convinient for users.
Thanks for replying...
any other advises how to upload data from excel?
Mar 26 '07 #3
MMcCarthy
14,534 Expert Mod 8TB
I'm trying to pursue the first suggested solution but some values are still getting lost during the conversion. for example:
excel file:
invoice number
1234
1235
1236
...

line 250: 1234df6

well, access drops line 250 because based on first 25 records it determined the field to be an integer, even tho I specify it as text in the destanation table... so it takes it as an integer uploads it and then converts in to text as specified in the table and that the problem I'm trying to work around.
second option is not convinient for users.
Thanks for replying...
any other advises how to upload data from excel?
If you created the table then just go in and change the number format to Long Integer or text whichever suits.
Mar 26 '07 #4
is49460
25
I surely did that but seems that access looks at the assigned data type only after upload is completed.

Seems like access goes through the following steps during upload process:
1. Access takes first 25 records (as a sample) to determines the data type on its own, regardless whats specified in destanation table.
2. Uploads all records (loosing the once that dont correspond with #1, even tho they DO match the specified type)
3. assign specified data type

If you have extra couple of minutes create table in access with 1 field of text data type. create excel file with same heading as in access followed by 30 rows of integers (1..30) and then some string in 31st row.
If you perform import that last cell with string in it will get dropped even tho you specified for the column to be text.
if you got couple of minutes to try that, perhaps you would understand my problem better, which I already greatly appreciate you taking your time and replying.
Thanks.
Mar 26 '07 #5
MMcCarthy
14,534 Expert Mod 8TB
My apologies you are right.

I must admit I would never normally try to import a spreadsheet. Try the second option of converting it to a csv file and importing that instead.

Mary
Mar 26 '07 #6
Denburt
1,356 Expert 1GB
Yes, interesting indeed.
Mar 26 '07 #7
is49460
25
I'll perhaps end up writing automated macro to sort data in excel to have all strings appear up on top so access will recognize them as "text". The reason cvs file is not an option is just beacuse users get their data in excel format before they run it through DB. I want to simplify (and in the same time avoid) any data manipulations by them. Thanks for replying and if you come across any work around let me know.
Thank a lot.
Mar 26 '07 #8
Denburt
1,356 Expert 1GB
This is how I solved it, using code I would open the excel spreadsheet and save it as a text file. Then perform the following or something along these lines...
Expand|Select|Wrap|Line Numbers
  1.  Dim db As DAO.Database
  2.     Dim DskTop
  3.     Dim wsShell As New WshShell
  4.     Dim wsSCut As WshShortcut
  5.     Dim strCommandLine As String 'Command Line for shortcut to run
  6.   Set db = CurrentDb()
  7. DskTop = wsShell.SpecialFolders("Desktop")
  8.  
  9.     db.Execute _
  10.     "SELECT * INTO NewContact FROM [text;FMT=Delimited;HDR=Yes;DATABASE=" & DskTop & ";].[Book21#txt];", _
  11.     dbFailOnError
  12.     db.TableDefs.Refresh
  13.  
Mar 26 '07 #9
Denburt
1,356 Expert 1GB
Darn forgot to mention that you need to set up a schema and it should reside in the same folder. This also can be accomplished in code if you wanted to. My schema looks as such.

Schema.ini



[Book21.txt]
ColNameHeader=False
Format=FixedLength
MaxScanRows=0
CharacterSet=OEM
Col1="First Name" Char Width 10
Mar 26 '07 #10
is49460
25
This is how I solved it, using code I would open the excel spreadsheet and save it as a text file. Then perform the following or something along these lines...
Expand|Select|Wrap|Line Numbers
  1.  Dim db As DAO.Database
  2.     Dim DskTop
  3.     Dim wsShell As New WshShell
  4.     Dim wsSCut As WshShortcut
  5.     Dim strCommandLine As String 'Command Line for shortcut to run
  6.   Set db = CurrentDb()
  7. DskTop = wsShell.SpecialFolders("Desktop")
  8.  
  9.     db.Execute _
  10.     "SELECT * INTO NewContact FROM [text;FMT=Delimited;HDR=Yes;DATABASE=" & DskTop & ";].[Book21#txt];", _
  11.     dbFailOnError
  12.     db.TableDefs.Refresh
  13.  

Looks like it will be a good work around without limit to one field (the one thats sorted in my algorithm). Thanks a lot
Mar 26 '07 #11
Denburt
1,356 Expert 1GB
You are quite welcome!
Mar 26 '07 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
0
by: news | last post by:
I have no idea if this is a Linux issue or PHP. Looking for clues here. I have a PHP script which I use to upload a CSV spreadsheet into a mySQL database. (The script follows here in a sec.) I...
13
by: Allison Bailey | last post by:
Hi Folks, I'm a brand new Python programmer, so please point me in the right direction if this is not the best forum for this question.... I would like to open an existing MS Excel spreadsheet...
3
by: Brooke | last post by:
I am new to ASP.NET, but have been programming for about 14 years (C# about 2 years). My manager asked me to develop a web application that would allow employees to view a spreadsheet that is used...
9
by: Wayne Smith | last post by:
I've come up against a major headache that I can't seem to find a solution for but I'm sure there must be a workaround and I would really be grateful of any help. I'm currently building a web...
0
by: sradoff | last post by:
I wish to use XPath to access data from within an Excel generated XML Spreadsheet (generated with MS Excel 2003). I am using an asp Web page (not .NET, not at this time). I instantiate...
0
by: ssrirao | last post by:
There is an Excel Spreadsheet containing data, residing in an internet site. It’s very easy to Import data from a local Excel Spreadsheet into SQL Server Database Table using DTS. But in my case...
0
by: mix01 | last post by:
Hi, I am trying to get some VBA code working, but am preplex as to why it does not work. I would really appreciate any level of help. Many thanks, Mix01 Version of the program
21
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.