Hi ! can any of you help ?
Since datasheets and forms can happily display calculated fields over 255 characters long,
I was surprised to discover that the same when read via a DAO recordset beyond 255
characters is replaced with garbage.
I'd be interested in how many of you also experience this problem. To see if you have, try
one of the follow examples.
Example
----------
To display the last 60 of 300 'x's, press Ctrl-G and enter the following:
(*** TYPE AS ONE LINE ***)
?Mid(dbengine(0)(0).OpenRecordset("Select String(300,'x') From
MSysObjects").GetRows(1)(0,0),241)
If the above produced some 'x's followed by garbage, rather than entirely 'x's, then you
have the problem too.
The following clearly shows that the field calculations are actually carried out
correctly:
(*** TYPE AS ONE LINE ***)
?dbengine(0)(0).OpenRecordset("Select String(300,'x') As Str,Mid(Str,200) From
MSysObjects").GetRows(1)(1,0)
Details
--------
When an SQL calculated field exceeds 255 characters, the result is a Variable-Size Text
Field, Size 0.
The field displays fine in text boxes, datasheets and when using DLookup, but produces
garbage after the 255th character only when read programmatically with recordsets. This
garbage differs with whether you interrogate it as Recordset!Field or
Recordset!Field.Value, or RecordSet("Field") versus RecordSet!Field, or when you specify
such things as dbForwardOnly or not, etc.
Anything calculative seems to do this - functions returning over 255 characters, or just
simple equations like MemoFieldOver255Chr & 'xxx'. The calculations are performed
correctly internally, as the second example below shows.
Placing the SQL as the RecordSource of a form and using a TextBox to display the offending
field results in correct data, and then doing a Form.RecordSetClone and reading the source
data of that TextBox yields the usual garbage !!
If you Select Into a new Table you get truncation of the data to 255 chr
If you Insert Into an existing Table with the offending field a Memo, it is correctly
written
GetChunk etc fails as it thinks it is a Variable Size Text Field, Size 0
Reading through the garbage in a non-unicode loop from bytes 512 To 599 suggests no
particular rhyme or reason, as there are only a few fragmentary repeating numbers after
character 255 for a string that should be entirely repeating characters.
The *practical* problem arises particularly with generic functions carrying out actions
using recordsets (or Sql) passed as parameters, the only workaround I can see is to create
a temporary table with Memos, perform an Insert Into and read the data off, then delete
the table.
Environment
---------------
This occurs for me on Access 97, 2000 and 2002, latest service packs on both Jet and
Access.
I have XP Home edition but I asked someone on an entirely different OS, different
Access 97 and DAO service packs, and the results were the same.
I'd very much hope to hear what you folk find, and any solutions...
David