You are correct. Access and Excel cannot seem to
share Type Codes.
By 'Type Codes' do you mean data types? When Excel is used as a data
source its data types are a subset of Jet's (MS Access's) data types,
so actually they *do* share data types.
So no matter what I have the Format Code set for a Column
in the spreadsheet, Access interprets it depending on the number of entries
that are numeric in nature as opposed to Alpha-Numeric or straight lettered
text.
You've made a couple of incorrect assumptions there.
First, you can format the column to be of data type Text. This is
easily demonstrated by creating an Excel table of with a column of
type Text, inserting numeric values, then querying the data and
testing its data type e.g. (execute these statements individually):
CREATE TABLE
[Excel 8.0;HDR=YES;Database=C:\test.xls;].MyExcelTable
(MyTextCol VARCHAR(255) NULL)
;
INSERT INTO
[Excel 8.0;HDR=YES;Database=C:\test.xls;].MyExcelTable
(MyTextCol) VALUES (1.23)
;
INSERT INTO
[Excel 8.0;HDR=YES;Database=C:\test.xls;].MyExcelTable
(MyTextCol) VALUES (4.56)
;
INSERT INTO
[Excel 8.0;HDR=YES;Database=C:\test.xls;].MyExcelTable
(MyTextCol) VALUES (-78)
;
SELECT MyTextCol, TYPENAME(MyTextCol)
FROM
[Excel 8.0;HDR=YES;Database=C:\test.xls;].MyExcelTable
;
Second, MS Access is not interpreting the data type. The data type is
determined by Jet on the Excel side before it gets to MS Access
(perhaps more correctly to say, before it gets to Jet on the MS Access
side). If you were querying Excel data from, say, SQL Server, Jet
would determine the Excel data type before the data reached SQL
Server, so there's no point 'blaming' SQL Server in these
circumstances.
I found a trick which is a temporary work around
I created about 20 bogus records at the top
of the spreadsheet
not exactly
the fix I am looking for.
In the link I posted, it discusses the registry keys Jet uses to scan
the rows and resolve a mixed types situation. It should be clear (but
I admit, it may not be) that the registry settings may be changed in
your favor. In brief, set the registry key value TypeGuessRows to 0
(zero) and ensure the ImportMixedTypes reg key is Text (the default
value). All rows will be scanned and it will take just one value with
a different data type for a mixed types situation to be detected and
the column will be 'seen' as Text.
Strange no one else has asked MS about this
issue.. I certainly can't be the only one having it!
I see questions about this issue in these newsgroups practically every
day. I'm not sure asking MS would get you anywhere. It is most
definitely a design feature rather than a bug. A different design
choice was made for text files, where a schema.ini file (or import
specs for MS Access UI?) may be used to explicitly specify data type.
MS decided to do things differently for Excel, which is a shame
because the schema.ini file approach works well IMO. I think the
consensus is that MS will not be further developing Jet, other than to
address security issues.
Jamie.
--