LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default ADO inserts text strings not numbers when table is empty

Bit of a stab in the dark this one. We're using standard ADO to access data
stored in an Excel workbook (don't ask why) and have a slight problem.
Consider a simple sheet containing the following heading and data:

Col1,Col2
1,3
2,4

If you execute a command like this:

Dim cmd As New ADODB.Command
cmd.Connection=ActiveConnection
cmd.CommandText="Insert Into [Data$] (Col1,Col2) Values (3,5)"
cmd.Execute

It works fine - the extra row is added contain the two *numbers* 3 & 5.
HOWEVER, if you delete the data rows out of the worksheet/table leaving just
the headings and carry out the same command, two *text* strings are written,
i.e. '3 and '5. I'm assuming that this is because Excel is unable to
determine the data types of the fields when the table is empty and therefore
defaults to text.

This can be confirmed by opening up a recordset on the empty table and
delving around the Fields collection. When the table is empty, Fields(0) is
a text string. However, then when with numbers, Fields(0) is a double.

Is there anyway around this? Some way to tell Excel the data types of the
fields in an empty Excel table?

Cheers, Rob.


 
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
find and replace numeric strings in larger text strings Mr Molio Excel Worksheet Functions 8 November 9th 11 05:17 PM
Empty strings appear as zeros Paul Martin[_2_] Charts and Charting in Excel 5 May 9th 08 12:37 AM
How can I convert empty strings to empty cells? Shane Excel Discussion (Misc queries) 2 July 19th 05 12:10 PM
2 more questions about extracting numbers from text strings andy from maine Excel Discussion (Misc queries) 0 March 28th 05 09:47 PM
Clear Empty Strings Tim Tabor Excel Programming 3 October 6th 03 02:12 AM


All times are GMT +1. The time now is 01:34 AM.

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

About Us

"It's about Microsoft Excel"