简体   繁体   中英

MS Access Memo field truncated

This issue sounds familiar, but please read it to the end, as it has a twist to similar questions I found in this forum or elsewhere. I am using Access 2010 to build a simple app to create some code to execute in another system. Part of it is to convert number of records per user into a single record, with all user entries separated by comma. To illustrate, here is the sample of my input:

USER    MBR
----    ---- 
USR1    DRG 
USR1    ABC 
USR1    XYZ 
USR2    123A 
USR2    ABS2

And I need it in this format:

USER   MBR_LIST
-----  ---------------
USR1   DRG, ABC, XYZ
USR2   123A, ABS2

So far, so familiar. I've used the code posted by Allen Brown back in 2008 ( http://allenbrowne.com/func-concat.html ), but I've run into an issue. The code works fine - when I debug it, I can see that my output string ("strOut") has all MBRs for a single user, as expected. Mind you, sometimes this string is over 7,000 char long. So, again following some great advice found around, I've created a table with the MBR_LIST field set to MEMO, and I execute Allen's function as:

INSERT INTO Table2 ( [USR], MBR_LIST )
SELECT B.USR, ConcatRelated("MBR","Table1","Table1.USR = '" & B.USR & "'","USR") AS Mbr_List
FROM (SELECT Table1.USR FROM Table1 GROUP BY Table1.USR)  AS B;

(NOTE: the query is built as such to avoid doing Group By on the Memo field, which is known to be truncating the Memo field)

Still, after doing this, my MBR_LIST field in the table shows only 320 chars (?).

I even tried adding an empty row, as suggested in this post: MS Access Create Table is Truncating Memo Field , but with no success - the field still gets truncated to 320 chars:

INSERT INTO Table2 ( [USR], MBR_LIST )
SELECT B.USR, "" as Mbr_List
FROM [Table2] as B Where (False)
UNION ALL
SELECT B.USR, ConcatRelated("MBR","Table1","Table1.USR = '" & B.USR & "'","USR") AS Mbr_List
FROM (SELECT Table1.USR FROM Table1 GROUP BY Table1.USR)  AS B;

As a last resort, using the MID() I've created 20 "chunks" of 300 chars each (Mbr_1 to Mbr_20) in my SELECT statement, and I got them all back fine. Then I wrapped this into another SELECT with those chunks concatenated (Mbr_1 & Mbr_2 & ... & Mbr_20) AS Mbr_LIST, and got - 320 chars!

Any ideas why and how to insert/display the full string created by the function?

Thanks, tribe

There is a workaround I created years ago using DLookup in a helper function.

Not the fastest, of course, but if anything else fails ...

Access Query truncates Memo Field

To insert a long text, use VBA when you have retrieved the values for USR and MBR_LIST:

Dim rs As DAO.Recordset

Set rs = CurrentDb.OpenRecordset("Select [USR], MBR_LIST From Table2")

rs.AddNew
    rs!USR.Value = USR
    rs!MBR_LIST.Value = MBR_LIST
rs.Update
rs.Close

Set rs = Nothing

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM