Truncation Issue w/ Strings 
Author Message
 Truncation Issue w/ Strings

I have an access database that has a field (type memo) that keeps very
long strings. When the value of this field is very long, my Visual
Basic 6.0 code does not return the whole value and truncates it. I
just read it using standard code like this:

storeId = rstMsg!storeId

where is defined as: Dim  stMsg As ADOdb.Recordset

Everything works fine if storeid is not very big.

Does anybody know why this happens?

Thanks,

-Jalil



Tue, 04 Jan 2011 08:30:47 GMT  
 Truncation Issue w/ Strings
Hello,
I just had a similar problem today with this type of thing, I posted the
question into the microsoft.public.access newsgroup along with the solution
I arrived at.

Essentially what I found was that access was returning the field as a
Text(255) field, and so it was truncating the string at 255.  The weird
thing was that the in ado, when I read the value of the field, it would
return a string of the correct length, with the first 255 bytes containing
data from the table, and the rest seemed to be reading memory from other
processes, I could see environment information, system stuff, etc.. very
odd.

I was getting the results from an access query, so I ended up having to
create a temp table, and insert the rows into a memo field in the temp
table, then I could read from it...  Very bazaar.

Delow is the text from my message in the other group in case it helps.

Ok, I found a work around, I don't know how great it is, but oh well..

Anyway, if anyone is interested, here it is:
In VBA code:
1. open a recordset from the query
2. Create a temp table
3. append the fields from the query into the temp table.  If the recordset
field is text, change it to memo in the temp table.
4. execute the query as an insert into query into the temp table.
5. select from the temp table.

voila the values don't get truncated

--
Support Fairtax Legislation
www.fairtax.org

"A government big enough to give you everything you want, is strong enough
to take everything you have."
-Thomas Jefferson


Quote:
> Hi,
> I have a problem with an access DB app.  It seems pretty straightforward,
> but it is giving me all kinds of grief.

> I have a query that calls a function to get a list of descriptions ie:

> I can reproduce the behavior very easily by creating a module, and adding
> the following:

> Function getList() As String
>    getList = "fdsjaklfh shfd slhfjdlsh jfdaj fdhsjflhsjflhjd sahfjdsha
> jfdhsjf hdsafhdsj fhjdshfjdsajsdk fhsdhfjdshf jsdhfjshjf hdsjfhjsdahfjsda
> h " & _
>    "fdhsjak hfdjksh fdshfjkdlsh fjdshfj hdslfh dshfjlshjfhdsjflhdsjlfh
> dsjlkhfjdshfjdha jfdhj f " & _
>    "fdhsjak hfdjksh fdshfjkdlsh fjdshfj hdslfh dshfjlshjfhdsjflhdsjlfh
> dsjlkhfjdshfjdha jfdhj f " & _
>    "fdhsjak hfdjksh fdshfjkdlsh fjdshfj hdslfh dshfjlshjfhdsjflhdsjlfh
> dsjlkhfjdshfjdha jfdhj the end "
> End Function

> Sub test()
>    Dim rs As Recordset2
>    Set rs = CurrentDb.OpenRecordset("Select * from query1")
>    debug.print rs("Expr1")
> End Sub

> Then create query1 as the following:
> SELECT getList() AS Expr1;

> you will see that it shows the first few characters (I think it's 255, but
> I haven't actually counted), but then just a bunch of garbage after that.
> If I open query1 in the access front end, it works just fine, but I can't
> get at the data from within the code.  Is there a trick I am not aware of
> to do this?



Tue, 04 Jan 2011 11:35:47 GMT  
 Truncation Issue w/ Strings

Quote:
>I have an access database that has a field (type memo) that keeps very
> long strings. When the value of this field is very long, my Visual
> Basic 6.0 code does not return the whole value and truncates it. I
> just read it using standard code like this:

> storeId = rstMsg!storeId

> where is defined as: Dim  stMsg As ADOdb.Recordset

> Everything works fine if storeid is not very big.

> Does anybody know why this happens?

You might want to look into the GetChunk() method of the Field object.


Tue, 04 Jan 2011 21:14:03 GMT  
 Truncation Issue w/ Strings
Could you be a little less ambiguous than "big" & "very long", for some
people a "big" string will be a few hundred characters for others it's not
"very long" if its under a megabyte.

Also is "stMsg" as typo for "rstMsg"? or are you talking about different
things here.
This is an admittedly trivial example of why you should ALWAYS copy and
paste from your code rather than re-typing it into the message.

Regards - Dave O.


Quote:
>I have an access database that has a field (type memo) that keeps very
> long strings. When the value of this field is very long, my Visual
> Basic 6.0 code does not return the whole value and truncates it. I
> just read it using standard code like this:

> storeId = rstMsg!storeId

> where is defined as: Dim  stMsg As ADOdb.Recordset

> Everything works fine if storeid is not very big.

> Does anybody know why this happens?

> Thanks,

> -Jalil



Tue, 04 Jan 2011 21:26:03 GMT  
 Truncation Issue w/ Strings

Quote:
> Could you be a little less ambiguous than "big" & "very long", for some
> people a "big" string will be a few hundred characters for others it's not
> "very long" if its under a megabyte.

> Also is "stMsg" as typo for "rstMsg"? or are you talking about different
> things here.
> This is an admittedly trivial example of why you should ALWAYS copy and
> paste from your code rather than re-typing it into the message.

> Regards - Dave O.



> >I have an access database that has a field (type memo) that keeps very
> > long strings. When the value of this field is very long, my Visual
> > Basic 6.0 code does not return the whole value and truncates it. I
> > just read it using standard code like this:

> > storeId = rstMsg!storeId

> > where is defined as: Dim ?stMsg As ADOdb.Recordset

> > Everything works fine if storeid is not very big.

> > Does anybody know why this happens?

> > Thanks,

> > -Jalil

I posted this to another group too and Allen Browne pointed me at this
great page:

    http://allenbrowne.com/ser-63.html

which explains why it happened. I thought I let everybody know. In my
case, I had to change my Select Distinct to just Select so no data
processing happens on MEMO field.

Thanks everybody for the great help,

-Jalil



Tue, 04 Jan 2011 22:16:32 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Getting ADO Error- String Truncation

2. Getting ADO Error - String Truncation

3. string truncation with crystal reports 8.5 and sql server 7

4. Right String Truncation in SQLServer 2000

5. 01004 - 0 - [Microsoft][ODBC SQL Server Driver]String data, right truncation

6. -2147217889 [ODBC SQL Server Driver] String Data, Right Truncation

7. String Truncation

8. VB7 String Performace Issue

9. String.Intern Comparison Issues.

10. String Resource Issue

11. Unicode <-> single-byte string issues

12. Err 3759 Scaling of decimal value resulted in data truncation

 

 
Powered by phpBB® Forum Software