473,581 Members | 2,220 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_TESTLONGST RING" with one field:

LongString:getL ongString()

3. Create a test public function:

public Function testGetLongStri ng()
dim r as recordset
set r = currentdb.openr ecordset("QRY_T ESTLONGSTRING")
testGetLongStri ng = r.fields(0) ' or r.fields(0).Val ue for slightly
different results, still mangled
set r = nothing
End Function

4. Open the immediate pane (Ctrl-G)

write

? testGetLongStri ng

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 5880
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_TESTLONGST RING" with one field:

LongString:getL ongString()

3. Create a test public function:

public Function testGetLongStri ng()
dim r as recordset
set r = currentdb.openr ecordset("QRY_T ESTLONGSTRING")
testGetLongStri ng = r.fields(0) ' or r.fields(0).Val ue for slightly
different results, still mangled
set r = nothing
End Function

4. Open the immediate pane (Ctrl-G)

write

? testGetLongStri ng

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).Typ e

after the line

set r = currentdb.openr ecordset("QRY_T ESTLONGSTRING")

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_TESTLONGST RING" with one field:

LongString:getL ongString()

3. Create a test public function:

public Function testGetLongStri ng()
dim r as recordset
set r = currentdb.openr ecordset("QRY_T ESTLONGSTRING")
testGetLongStri ng = r.fields(0) ' or r.fields(0).Val ue for slightly
different results, still mangled
set r = nothing
End Function

4. Open the immediate pane (Ctrl-G)

write

? testGetLongStri ng

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).Typ e

after the line

set r = currentdb.openr ecordset("QRY_T ESTLONGSTRING")

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 theLongStringFu nction,
theRecordset.Fi elds(theParamet erFieldName)

- 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_TESTLONGST RING" with one field:

LongString:getL ongString()

3. Create a test public function:

public Function testGetLongStri ng()
dim r as recordset
set r = currentdb.openr ecordset("QRY_T ESTLONGSTRING")
testGetLongStri ng = r.fields(0) ' or r.fields(0).Val ue for slightly
different results, still mangled
set r = nothing
End Function

4. Open the immediate pane (Ctrl-G)

write

? testGetLongStri ng

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).Typ e

after the line

set r = currentdb.openr ecordset("QRY_T ESTLONGSTRING")

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
2050
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, Inserting records works fine, but my headache is the searchform.. Whatever i type in the searchbox (sok), the result is all database entries, not...
4
1964
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 memo still cuts it short. TransferText cut it short too. Someone suggested that I use the following code. It works, but it populates only one row of...
2
2955
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 2000 chracters. Right now the code looks like this: Private Sub Command3_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)...
2
2139
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 Null. I tried by "Control Source=Count( Is Not Null), but it doesn't work, it still counts all rows, even with Null. How to set Control Source in...
2
3606
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 to use this calculated field: If rsGPValue.Fields("OurDate") > {Forms]!!.Value
13
3416
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 of the form which is submit and cancel. After i have clicked submit, the information is stored directly into my corresponding database table. My...
1
13236
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 in database there are only two Columns:
21
2885
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: Database name: sp Table: importer Field names: imp_code, imp_name, imp_address, imp_tel
2
1998
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 GetCSV_FileData() Dim cnn As ADODB.Connection Dim cn As ADODB.Connection Dim rs As ADODB.Recordset Dim f As Integer Dim NumberOfRows As Integer
0
8149
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8304
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7899
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8175
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6553
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5364
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3805
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1403
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1138
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.