Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to Retrieve data from a memo field

Posted on 2004-10-11
11
Medium Priority
?
482 Views
Last Modified: 2008-02-26
Hi,
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 :
ABCDdrf
CDFRnh

2nd record :
DSERtrez
JKPDaaan
EFDRxx

3rd record :
DDDEs

I want to get the following data :
ABCD
CDFR
DSER
JKPD
EFDR
DDDE

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

Thank's for your help
0
Comment
Question by:MSelect
11 Comments
 
LVL 11

Expert Comment

by:Jokra_the_Barbarian
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))

wend
0
 

Author Comment

by:MSelect
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 !
0
 
LVL 11

Expert Comment

by:Jokra_the_Barbarian
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.
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
LVL 26

Accepted Solution

by:
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
    objStream.Open
   
    '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
    Loop
    .MoveNext
  Wend
End With



output:
ABCD
CDFR
DSER
JKPD
EFDR
DDDE




Alan
0
 
LVL 11

Expert Comment

by:Jokra_the_Barbarian
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?
-Jokra
0
 
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.

Alan
0
 
LVL 52

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.

/gustav
0
 
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...


Alan
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Creating a Cordova application which allow user to save to/load from his Dropbox account the application database.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Suggested Courses

916 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