Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


How to Retrieve data from a memo field

Posted on 2004-10-11
Medium Priority
Last Modified: 2008-02-26
I need your help !
Working with VB6, I have an Access database table (accessed with DAO) named "Table1" with a single MEMO field, named "Field1" and containing text lines (i.e. separated with CHR(13) & CHR(10))

I want to retrieve the 4 first characters of every line of every record. For example

1st record :

2nd record :

3rd record :

I want to get the following data :

... but I'm unable to write the right SQL query ! Is it possible ?

Thank's for your help
Question by:MSelect
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 11

Expert Comment

ID: 12276733
Try setting your output field to a function. Pass the memo field value into the function and get a string back. Use something similar to this within the function:

spos = 1

while spos<>0

  newStr = newStr & mid(oldStr, spos, 4) & chr(13)
  spos   = InStr(spos, oldStr, char(10))


Author Comment

ID: 12277076
Hummmm ...
If I well understand, it's what I currently do when I read a single record to get the first chars of every line but what I want is to buid a new Table by using a single query only once. It would take too much time in reading every record successively !
LVL 11

Expert Comment

ID: 12277370
The only way to get what you want is to parse the memo field for each record. Memo fields are large and parsing unfortunately takes time. If you are building a table, then you will only be running this query once.

I don't know of any other way to get what you want without parsing.
Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

LVL 26

Accepted Solution

Alan Warren earned 2000 total points
ID: 12278913
Hi MSelect

Use the ADODB.Stream

Reference: Microsoft ActiveX Data Objects 2.6 Lib

Dim objStm As ADODB.Stream

Dim strSql As String
Dim strLine As String

strSql = "select Field1 from table1"
Set objRs = New ADODB.Recordset
objRs.Open strSql, CurrentProject.Connection, adOpenForwardOnly, adLockReadOnly
' If not inside access you will need to instantiate a connection object
' to use in place of CurrentProject.Connection.

With objRs
  While Not .EOF
    'Instantiate and open stream
    Set objStream = New Stream
    'Set line separator to line feed
    objStream.LineSeparator = adCRLF   ' or use adLF
    'Load text content Field1 into stream
    objStream.WriteText .Fields("Field1"), adWriteLine
    objStream.Position = 0
    Do Until objStream.EOS
        strLine = Left(objStream.ReadText(adReadLine), 4)
        Debug.Print strLine
End With


LVL 11

Expert Comment

ID: 12279068
Hey Alan, that's pretty slick. While you are still iterating through the recordset, I would think that this streaming example would be faster than parsing? Have you done any performance comparisons?
LVL 26

Expert Comment

by:Alan Warren
ID: 12283117
Hi Jokra,

Thanks for the thumbs up :)

No not done any comparisons, I use streams a lot with blobs, so I am familiar with the syntax, they seem fairly robust to me. Memo field is basically a BLOB field (Binary) so I thought the ADODB.Stream was the way to go here.

Regarding speed, streams are in memory, so they cant take that long to process.

LVL 51

Expert Comment

by:Gustav Brock
ID: 12285120
The streaming method is nice but - using DAO - why not just open the new (empty) table and the input table, read record by record of the input table, for each record read the memo field, and for each line in the memo field do an AddNew to the new table appending a record with the four chars.

If you wrap this in BeginTrans and CommitTrans it will run very fast.

LVL 26

Expert Comment

by:Alan Warren
ID: 12511402
Hi Venabili,

First of all let me say I really appreciate the excellent cleanup job you are doing, THANK YOU.
Personally I think cleanup operators should get a points commission on all Q's, similar to debt collection agent. - LOL

I am most interested in this questions final disposition, I am most interested in some feed-back from the author regarding the solution I proffered, it was tested and tried before I posted.

Take care...


Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lotus Notes has been used since a very long time as an e-mail client and is very popular because of it's unmatched security. In this article we are going to learn about  RRV Bucket corruption and understand various methods to Fix "RRV Bucket Corrupt…
In this article, I’ll look at how you can use a backup to start a secondary instance for MongoDB.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

730 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