Link to home
Start Free TrialLog in
Avatar of Patrick Miller
Patrick MillerFlag for United States of America

asked on

String field to a memo field is not working

When I run the function below I am reading several records and combining note_text into catnote2.
If catnote2 has a note with 400 characters in it then when I put it in a query it shows up as only having 255 characters.  I know a text field has a default length of 255 but I would rather drop it into a memo field that has the ability to have more than the 255.    How do I format the sql query to allow for the memo field instead of the text field.  If there is a better way I am open for that also.

Here is the SQL query I am running. I have the cat_note2 module under it.  

SELECT tbl_cat_detail_notes.[CUST ID], tbl_cat_detail_notes.[Cust Name], tbl_cat_detail_notes.noteindex, formatMemo(cat_note2([noteindex])) AS Notes_total
FROM tbl_cat_detail_notes
GROUP BY tbl_cat_detail_notes.[CUST ID], tbl_cat_detail_notes.[Cust Name], tbl_cat_detail_notes.noteindex, cat_note2([noteindex]);


_________________________________________________________________________________________
Function cat_note2(the_index As String) As String
Dim db As dao.Database
Dim rs As dao.Recordset
Dim strsql As String
Dim string_note As String
strsql = "select ([NOTE_TEXT]) AS Notes from tbl_CAT_Detail_Notes where noteindex = '" & the_index & "' order by detailnoteindex;"
Set db = CurrentDb()
Set rs = db.OpenRecordset(strsql)
rs.MoveFirst
Do While Not rs.EOF
If string_note = "" Then
string_note = Trim(Right(rs!Notes, 76))
MsgBox string_note
Else
string_note = string_note & " " & Trim(Right(rs!Notes, 76))
MsgBox string_note
End If
rs.MoveNext
Loop

cat_note2 = (string_note)

End Function
Avatar of Leigh Purvis
Leigh Purvis
Flag of United Kingdom of Great Britain and Northern Ireland image

Do you really need the Group By clause?
Is [CUST ID] not unique?
And the group by is probably doing the supression.
ASKER CERTIFIED SOLUTION
Avatar of Leigh Purvis
Leigh Purvis
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Or if you prefer...

SELECT Temp.*, cat_note2(Temp.[noteindex])
  FROM
   (SELECT tbl_cat_detail_notes.[CUST ID], tbl_cat_detail_notes.[Cust Name], tbl_cat_detail_notes.noteindex
    FROM tbl_cat_detail_notes
    GROUP BY tbl_cat_detail_notes.[CUST ID], tbl_cat_detail_notes.[Cust Name], tbl_cat_detail_notes.noteindex) AS Temp

In case of slight performance difference. :-)
Please note that a memo field can hold more than 255 characters but only the first 255 characters are searchable.  
Avatar of IainTheVBALearner
IainTheVBALearner

Hello.

This is unrelated to the question, but regarding KComputers statement that only the first 255 characters of a memo field are searchable.  What makes you say this?

I have a recipies database.  I have memo fields for method and ingredients.  I can search through them no problem.  Some of my fields are thousands of characters in length.  I just tried searching for words at the end and found them.

Iain
Sorry, I'm going by the books.  Can't say that I've ever messed with it at any great length.  What search method do you use?  SQL statement?  The binoculars?
Memo fields have their limitations (but as displayed there's usually a workaround or two) but matching within them isn't one of them - unless you're searching on a query which has already truncated the field of course! :-S

But that's the whole point of this question isn't it - to get around that...
HK.  I use the Like operator in an SQL query (Like "*" & [StringToSearchFor] & "*")
I'm seeing that my understanding of memo field limitations was indeed incorrect.  A memo field does have limitations.  Consider the following quote from Microsoft's website:

"You can sort or group on a Text field or a Memo field, but Access only uses the first 255 characters when you sort or group on a Memo field."

A quote from another perplexed user:
http://experts.about.com/q/Using-MS-Access-1440/MS-Access-2002-MEMO-2.htm

"You know it's coming... BUT when I copy-paste into my pretty form, that crazy Memo field cuts off at exactly the 255th character. Sure, it acts like it's accepting the whole clipboard contents, but as soon as I scroll to the next record and come back, whatever beyond 255 in the Memo field is gone."




There are lots of posts/articles on the web about memo fields having 255 character limitations.  It appears to me copy/paste or import/export errors.  Perhaps this doesn't apply to this particular question at all but it may be something to consider.

The problem seems to be in the way a memo field is stored.  Only the first 255 characters are stored in the database; the rest are stored in a seperate "memo file."  Depending where you query/search/cut/copy/export the data from, you might only be getting the 255 characters that are stored in the database.  It seems this limitation was worse with 97 and 2000 versions of Access but you will find posts about it when using 2002 also.

Avatar of Patrick Miller

ASKER

I was able to store the data in a memo field and it retained the whole note.   I have some that are 400 characters after being consolidated.

Thanks.
Welcome :-)