473,396 Members | 2,026 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Unable to retrieve long string from calculated field through recordset

The problem is (using MS Access 2003) I am unable to retrieve long
strings (255 chars) from calculated fields through a recordset.

The data takes the trip in three phases:

1. A custom public function returns a long string. This works.

2. A query has a calculated field based on the custom function above.
This works when the query is run directly.

3. A recordset is opened based on the query in 2, but retrieving the
long string through the recordset field fails.

What is returned is the first 255 characters correctly, then the rest
of the string is mangled ("funny" characters).

To reproduce this problem:

1. Create a custom function:

public Function getLongString()
getLongString = String(254,".") & "X" & String(255,"A")
End Function

2. Create a new query named "QRY_TESTLONGSTRING" with one field:

LongString:getLongString()

3. Create a test public function:

public Function testGetLongString()
dim r as recordset
set r = currentdb.openrecordset("QRY_TESTLONGSTRING")
testGetLongString = r.fields(0) ' or r.fields(0).Value for slightly
different results, still mangled
set r = nothing
End Function

4. Open the immediate pane (Ctrl-G)

write

? testGetLongString

5. hit Enter to run the function and see the output

You will see that the dots up to the "X" are output correctly, but the
"A"'s appear as random characters (mangled).

I have not been able to find a workaround for this, and would be most
grateful for ideas.

Thanks,

- Henrik

Dec 7 '06 #1
5 5860
An Access Table field of type Text has a limit of 255 chars. Try
setting your recordset object to a memo field for the long string.

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Dec 7 '06 #2

Henrik wrote:
The problem is (using MS Access 2003) I am unable to retrieve long
strings (255 chars) from calculated fields through a recordset.

The data takes the trip in three phases:

1. A custom public function returns a long string. This works.

2. A query has a calculated field based on the custom function above.
This works when the query is run directly.

3. A recordset is opened based on the query in 2, but retrieving the
long string through the recordset field fails.

What is returned is the first 255 characters correctly, then the rest
of the string is mangled ("funny" characters).

To reproduce this problem:

1. Create a custom function:

public Function getLongString()
getLongString = String(254,".") & "X" & String(255,"A")
End Function

2. Create a new query named "QRY_TESTLONGSTRING" with one field:

LongString:getLongString()

3. Create a test public function:

public Function testGetLongString()
dim r as recordset
set r = currentdb.openrecordset("QRY_TESTLONGSTRING")
testGetLongString = r.fields(0) ' or r.fields(0).Value for slightly
different results, still mangled
set r = nothing
End Function

4. Open the immediate pane (Ctrl-G)

write

? testGetLongString

5. hit Enter to run the function and see the output

You will see that the dots up to the "X" are output correctly, but the
"A"'s appear as random characters (mangled).

I have not been able to find a workaround for this, and would be most
grateful for ideas.

Thanks,

- Henrik
I have seen a couple of references to this problem over the years in
the newsgroups but never any solutions. It appears that the problem
occurs when DAO has to decide what datatype to use for the calculated
fields in your recordset. Apparently when DAO encounters a calculated
field that returns a VBA 'string' datatype it decides to assign the
dbText type (rather than the more appropriate dbMemo) to the
corresponding recordset field (you can confirm this by inserting the
line

debug.print r.fields(0).Type

after the line

set r = currentdb.openrecordset("QRY_TESTLONGSTRING")

in your function above). The only suggestion I could offer is that you
use your query to populate a temporary table that explicitly uses a
memo field to store the output of your calculated field. Then you
could base a recordset on the temporary table and rest assured that DAO
will use the correct datatype for the fields. Other than that you'll
have to rewrite your process so that you don't base a recordset field
on the long calculated field returned by your query, i.e., shift more
processing to the SQL engine or to the VBA engine.

Bruce

Dec 7 '06 #3
Thanks Bruce,

The calculated field is indeed a dbText type. I rather thought there
was no straightforward solution.

Best,

- Henrik

de***************@gmail.com wrote:
Henrik wrote:
The problem is (using MS Access 2003) I am unable to retrieve long
strings (255 chars) from calculated fields through a recordset.

The data takes the trip in three phases:

1. A custom public function returns a long string. This works.

2. A query has a calculated field based on the custom function above.
This works when the query is run directly.

3. A recordset is opened based on the query in 2, but retrieving the
long string through the recordset field fails.

What is returned is the first 255 characters correctly, then the rest
of the string is mangled ("funny" characters).

To reproduce this problem:

1. Create a custom function:

public Function getLongString()
getLongString = String(254,".") & "X" & String(255,"A")
End Function

2. Create a new query named "QRY_TESTLONGSTRING" with one field:

LongString:getLongString()

3. Create a test public function:

public Function testGetLongString()
dim r as recordset
set r = currentdb.openrecordset("QRY_TESTLONGSTRING")
testGetLongString = r.fields(0) ' or r.fields(0).Value for slightly
different results, still mangled
set r = nothing
End Function

4. Open the immediate pane (Ctrl-G)

write

? testGetLongString

5. hit Enter to run the function and see the output

You will see that the dots up to the "X" are output correctly, but the
"A"'s appear as random characters (mangled).

I have not been able to find a workaround for this, and would be most
grateful for ideas.

Thanks,

- Henrik

I have seen a couple of references to this problem over the years in
the newsgroups but never any solutions. It appears that the problem
occurs when DAO has to decide what datatype to use for the calculated
fields in your recordset. Apparently when DAO encounters a calculated
field that returns a VBA 'string' datatype it decides to assign the
dbText type (rather than the more appropriate dbMemo) to the
corresponding recordset field (you can confirm this by inserting the
line

debug.print r.fields(0).Type

after the line

set r = currentdb.openrecordset("QRY_TESTLONGSTRING")

in your function above). The only suggestion I could offer is that you
use your query to populate a temporary table that explicitly uses a
memo field to store the output of your calculated field. Then you
could base a recordset on the temporary table and rest assured that DAO
will use the correct datatype for the fields. Other than that you'll
have to rewrite your process so that you don't base a recordset field
on the long calculated field returned by your query, i.e., shift more
processing to the SQL engine or to the VBA engine.

Bruce
Dec 8 '06 #4
Bruce,

The workaround I've implemented is a real hack:

I pass my handling routine the ordinal index of the calculated field in
the recordset, the name of the function for the calculated field, and
the fieldname of the recordset field value to be used as the parameter
to the calculated field function.

Then I store the return value of the calculated field in a variable,
and (for the calculated field) check to see if it is greater than 255
characters. If it is, I assume it is mangled. I then run the
calculating function directly using Application.Run and the appropriate
arguments. That works. Ugly, but it works.

The salient line is

theValue = Application.Run theLongStringFunction,
theRecordset.Fields(theParameterFieldName)

- Henrik

de***************@gmail.com wrote:
Henrik wrote:
The problem is (using MS Access 2003) I am unable to retrieve long
strings (255 chars) from calculated fields through a recordset.

The data takes the trip in three phases:

1. A custom public function returns a long string. This works.

2. A query has a calculated field based on the custom function above.
This works when the query is run directly.

3. A recordset is opened based on the query in 2, but retrieving the
long string through the recordset field fails.

What is returned is the first 255 characters correctly, then the rest
of the string is mangled ("funny" characters).

To reproduce this problem:

1. Create a custom function:

public Function getLongString()
getLongString = String(254,".") & "X" & String(255,"A")
End Function

2. Create a new query named "QRY_TESTLONGSTRING" with one field:

LongString:getLongString()

3. Create a test public function:

public Function testGetLongString()
dim r as recordset
set r = currentdb.openrecordset("QRY_TESTLONGSTRING")
testGetLongString = r.fields(0) ' or r.fields(0).Value for slightly
different results, still mangled
set r = nothing
End Function

4. Open the immediate pane (Ctrl-G)

write

? testGetLongString

5. hit Enter to run the function and see the output

You will see that the dots up to the "X" are output correctly, but the
"A"'s appear as random characters (mangled).

I have not been able to find a workaround for this, and would be most
grateful for ideas.

Thanks,

- Henrik

I have seen a couple of references to this problem over the years in
the newsgroups but never any solutions. It appears that the problem
occurs when DAO has to decide what datatype to use for the calculated
fields in your recordset. Apparently when DAO encounters a calculated
field that returns a VBA 'string' datatype it decides to assign the
dbText type (rather than the more appropriate dbMemo) to the
corresponding recordset field (you can confirm this by inserting the
line

debug.print r.fields(0).Type

after the line

set r = currentdb.openrecordset("QRY_TESTLONGSTRING")

in your function above). The only suggestion I could offer is that you
use your query to populate a temporary table that explicitly uses a
memo field to store the output of your calculated field. Then you
could base a recordset on the temporary table and rest assured that DAO
will use the correct datatype for the fields. Other than that you'll
have to rewrite your process so that you don't base a recordset field
on the long calculated field returned by your query, i.e., shift more
processing to the SQL engine or to the VBA engine.

Bruce
Dec 9 '06 #5
Henrik,

Thanks for sharing your solution.

Bruce

Dec 12 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Roar | last post by:
Hi! I have got 1 access 2000 DB, one simple search form, and 3 .asp pages (one for deleting a record, one for inserting a record and one for listing searchresults). Deleting records works fine,...
4
by: R Bolling | last post by:
I have a text file from a text document that has very long rows (two or three paragraphs from a text document for each row). Importing to text cuts it off at 255 characters, and importing to a...
2
by: Justin Koivisto | last post by:
I am attempting to execute a *long* query string via a ADODB.Recordset.Open (queryStr) call. Most of the time, the query string will be less than 100 characters, but in some cases, it may be up to...
2
by: Zlatko Matić | last post by:
I have a field and want to have a calculated field in a report that counts it. It had control source set to "=count (). As can be also Null, I would like it to count only values distinct from...
2
by: ey.markov | last post by:
Greetings, in A2K VBA, I set the following recordset: Set rsGPValue = dbs.OpenRecordset("SELECT *, DateSerial(Year(),Month()+4,0) FROM tblGPValue AS OurDate, dbOpenSnapshot) and then I try...
13
by: kev | last post by:
Hi all, I have created a database for equipments. I have a form to register the equipment meaning filling in all the particulars (ID, serial, type, location etc). I have two buttons at the end...
1
by: ahujasatna | last post by:
Hi all!! i am working on C#, ASP.Net with Sql server2000 and i am facing a problem, my Question is: "How to insert and retrieve images to/from Sqlserver2000 Database" I created a table...
21
by: giandeo | last post by:
Hello Experts. Is it possible to retrieve the value from a populated pull down menu from a database and then use that value to access the same database to get the related fields. Example: ...
2
by: vegeta456 | last post by:
I have a really strange problem. I am using Microsoft Access 2003 under Windows XP Professional. I am trying to read a CSV file using VBA in Access using the following procedure. Public Sub...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.