Solved

Access Query truncates Memo Field

Posted on 2014-11-10
7
213 Views
Last Modified: 2014-11-17
I have an Access Query partially made up of Memo Fields pulled from a Table.  My Query is set up as 'Select Top 1,' so that it only displays the first record-set.

Access truncates the data within the Memo Fields—cutting them off at 255 characters.

Does anyone know how to prevent this from happening?
0
Comment
Question by:mdstalla
7 Comments
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
Comment Utility
This is by design; any time you use a group by, distinct, you are going to get this type of behavior.  Without knowing what the rest of the query looks like, I cannot provide a clear solution, but it will involve a subquery.  Something like:

SELECT sq.*, T.MemoField
FROM (
SELECT Top 1 ID, Field1, Field2, Field3
FROM YourTable
ORDER BY SomeField) as sq
INNER JOIN yourTable as T
ON sq.ID = T.ID
0
 
LVL 45

Expert Comment

by:aikimark
Comment Utility
You might have a simpler query if you used a DLookup() function instead of a subquery.

Example:
SELECT Top 1 ID, Field1, Field2, Field3,
DLookup("memofld1", "MyTable", "ID=" & MyTable.ID) As MF1,
DLookup("memofld2", "MyTable", "ID=" & MyTable.ID) As MF2,
DLookup("memofld3", "MyTable", "ID=" & MyTable.ID) As MF3

FROM MyTable

Where (some row criteria goes here)

Open in new window

0
 
LVL 49

Expert Comment

by:Gustav Brock
Comment Utility
This is a known issue.
You can use this function:
Public Function LookupMemo( _
  ByVal strSource As String, _
  ByVal strFieldID As String, _
  ByVal strFieldMemo As String, _
  ByRef lngID As Long, _
  ByRef varMemo As Variant) _
  As String

' Extracts without truncation to 32768 characters the ' content of a memo field in a query.
'
' Assumes proper wrapping of table/field names containing spaces ' like "[My field name]" and a single field unique numeric key.
'
' Typical usage (SQL):
'
'   SELECT
'     ID,
'     LookupMemo("Table1", "ID", "MemoField", [ID], [MemoField]) AS FullMemo
'   FROM
'     Table1;
'
' 2003-12-29. Cactus Data ApS, CPH.

  ' Maximum length of string from memo field when retrieved in a query.
  Const clngStrLen  As Long = &H8000&

  Dim strExpr       As String
  Dim strDomain     As String
  Dim strCriteria   As String
  Dim strMemo       As String
  Dim lngLen        As Long
  
  On Error GoTo Exit_LookupMemo

  If Not IsNull(varMemo) Then
    lngLen = Len(varMemo)
    If lngLen < clngStrLen Then
      ' The memo field is not truncated.
      strMemo = varMemo
    ElseIf Len(strSource) > 0 And Len(strFieldID) > 0 And Len(strFieldMemo) > 0 Then
      ' The memo is probably truncated by the query.
      ' Lookup the full memo in strSource.
      strExpr = strFieldMemo
      strDomain = strSource
      strCriteria = strFieldID & " = " & lngID & ""
      strMemo = vbNullString & DLookup(strExpr, strDomain, strCriteria)
    End If
  Else
    ' Return empty string.
  End If
  
  LookupMemo = strMemo

Exit_LookupMemo:
  Exit Function
  
Err_LookupMemo:
  ' Return empty string.
  Resume Exit_LookupMemo
  
End Function

Open in new window

/gustav
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:mdstalla
Comment Utility
Hi Gustav:

Regarding the code you provided, where do I put this?
0
 
LVL 49

Accepted Solution

by:
Gustav Brock earned 500 total points
Comment Utility
Create a new module. Copy and paste.
Go to menu Debug. Click Compile.

/gustav
0
 

Author Closing Comment

by:mdstalla
Comment Utility
Yup, that seemed to work.  Thanks again for all of your help G!
0
 
LVL 49

Expert Comment

by:Gustav Brock
Comment Utility
You are welcome!

/gustav
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now