Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 441
Default Text file import using ADO - XL converts fields to dates

I am using Office 2003 on Windows XP with ADO 2.8.

I am using ADO to import the contents of a text file into several Excel
worksheets.
The program works great, BUT one field is a number separated by a forward
slash followed by another number. Examples: 12/0, 11/2, 24/5, 15/60.

For most rows (there around 128,000+), this field is imported correctly. For
several others, Excel converts them to dates and once converted, the original
values are lost. The raw text file is comma delimited and all fields are
surrounded by double quotes.

This behaviour occurs even when I import the first 65,536 rows using the
built-in parser when opening the text file manually. BEFORE import I can see
that the fields are correctly displayed, AFTER import they are changed - even
if I set all cells in the destination sheet to text type fields.

How can I fix this problem? I really prefer to use ADO if at all possible
since I have a whole program already dedicated to this project. Thanks much
in advance for your input.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default Text file import using ADO - XL converts fields to dates

The .Value property of an ADO Field is a variant data type. If you are not
doing so, I would suggest first that you explicity reference the .Value, for
example:
Range("A1").Value = MyRs.Fields(2).Value
instead of
Range("A1").Value = MyRs.Fields(2)

Then, to help it be recognized as text and not as a date, it might help to
assign it to a string variable:
Dim StrVar as String
StrVar = MyRs.Fields(2).Value
Range("A1").Value = StrVar

I haven't tested this so can't say if it will solve the problem, but hope it
might help.
--
- K Dales


"quartz" wrote:

I am using Office 2003 on Windows XP with ADO 2.8.

I am using ADO to import the contents of a text file into several Excel
worksheets.
The program works great, BUT one field is a number separated by a forward
slash followed by another number. Examples: 12/0, 11/2, 24/5, 15/60.

For most rows (there around 128,000+), this field is imported correctly. For
several others, Excel converts them to dates and once converted, the original
values are lost. The raw text file is comma delimited and all fields are
surrounded by double quotes.

This behaviour occurs even when I import the first 65,536 rows using the
built-in parser when opening the text file manually. BEFORE import I can see
that the fields are correctly displayed, AFTER import they are changed - even
if I set all cells in the destination sheet to text type fields.

How can I fix this problem? I really prefer to use ADO if at all possible
since I have a whole program already dedicated to this project. Thanks much
in advance for your input.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
opening text file converts numbers to scientific notation Ken Clark Excel Discussion (Misc queries) 1 March 22nd 10 06:37 AM
Import a txt file with text fields that have meaningful leading sp Muehe Excel Discussion (Misc queries) 2 April 3rd 08 11:48 PM
I'm trying to import fields from one Excel file to another Angel Incognito Excel Worksheet Functions 1 November 2nd 06 10:09 PM
converts numbers to dates jason2444 Excel Discussion (Misc queries) 2 February 10th 06 10:38 PM
Import Pipe Delimited File, Parse out certian Fields, create new f StarBoy2000 New Users to Excel 4 July 17th 05 07:36 AM


All times are GMT +1. The time now is 08:08 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"