PC Review


Reply
Thread Tools Rate Thread

Access 2000 - Loop through a Memo field with VBA

 
 
=?Utf-8?B?VG9ueV9WQkFDb2Rlcg==?=
Guest
Posts: n/a
 
      4th Apr 2006
I have a situation where we scan in documents and store the full text of the
document in a Memo field. Now, I need to write a VBA looping routine that
will loop through each character of the Memo field looking for various pieces
of information.

What is the best method for doing this? Are there limitations on trying to
read the entire Memo field into a string variable, or some other variable
type?
 
Reply With Quote
 
 
 
 
Douglas J. Steele
Guest
Posts: n/a
 
      4th Apr 2006
You shouldn't have any problem assigning the content of the field to a
string variable, and using the various Text functions.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"Tony_VBACoder" <(E-Mail Removed)> wrote in message
news:4D69D3F6-3718-4CC2-8E23-(E-Mail Removed)...
>I have a situation where we scan in documents and store the full text of
>the
> document in a Memo field. Now, I need to write a VBA looping routine that
> will loop through each character of the Memo field looking for various
> pieces
> of information.
>
> What is the best method for doing this? Are there limitations on trying
> to
> read the entire Memo field into a string variable, or some other variable
> type?



 
Reply With Quote
 
Dirk Goldgar
Guest
Posts: n/a
 
      4th Apr 2006
"Tony_VBACoder" <(E-Mail Removed)> wrote in
message news:4D69D3F6-3718-4CC2-8E23-(E-Mail Removed)
> I have a situation where we scan in documents and store the full text
> of the document in a Memo field. Now, I need to write a VBA looping
> routine that will loop through each character of the Memo field
> looking for various pieces of information.
>
> What is the best method for doing this? Are there limitations on
> trying to read the entire Memo field into a string variable, or some
> other variable type?


You can assign the field's value to a string variable, and use code like
this:

Dim strText As STring
Dim I As Long

strText = Nz(Me!MyMemoField, "")

For I = 1 To Len(strText)

If Mid(strText, I, 9) = "Something" Then
' found "Something" ...
End If

Next I

However, if you're looking for specific strings, it will be a *lot*
faster to use the InStr() function to locate them:

Dim strText As STring
Dim I As Long

strText = Nz(Me!MyMemoField, "")

I = InStr(strText, "Something")
If I > 0 Then
' found "Something" ...
End If

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


 
Reply With Quote
 
=?Utf-8?B?VG9ueV9WQkFDb2Rlcg==?=
Guest
Posts: n/a
 
      4th Apr 2006
Dirk and Doug, thanks for the assistance. I had the looping routine written,
but was concerned about string variables being truncated because memo fields
can be virtually anything. This brings me to Dirk's suggestion of using the
Instr function. Won't Access "choke" using Instr on a memo field because a
memo field could be virtually anything?

Also, in my situation, Instr, will not work, because I have to find many
instances of various values and then whatever follows that value. For
instance, I have to search for FirstName and then whatever is after
FirstName, to come up with the person's first name. But yes, that was a
great suggestion.

"Dirk Goldgar" wrote:

> "Tony_VBACoder" <(E-Mail Removed)> wrote in
> message news:4D69D3F6-3718-4CC2-8E23-(E-Mail Removed)
> > I have a situation where we scan in documents and store the full text
> > of the document in a Memo field. Now, I need to write a VBA looping
> > routine that will loop through each character of the Memo field
> > looking for various pieces of information.
> >
> > What is the best method for doing this? Are there limitations on
> > trying to read the entire Memo field into a string variable, or some
> > other variable type?

>
> You can assign the field's value to a string variable, and use code like
> this:
>
> Dim strText As STring
> Dim I As Long
>
> strText = Nz(Me!MyMemoField, "")
>
> For I = 1 To Len(strText)
>
> If Mid(strText, I, 9) = "Something" Then
> ' found "Something" ...
> End If
>
> Next I
>
> However, if you're looking for specific strings, it will be a *lot*
> faster to use the InStr() function to locate them:
>
> Dim strText As STring
> Dim I As Long
>
> strText = Nz(Me!MyMemoField, "")
>
> I = InStr(strText, "Something")
> If I > 0 Then
> ' found "Something" ...
> End If
>
> --
> Dirk Goldgar, MS Access MVP
> www.datagnostics.com
>
> (please reply to the newsgroup)
>
>
>

 
Reply With Quote
 
Douglas J. Steele
Guest
Posts: n/a
 
      4th Apr 2006
What do you mean by "virtually anything"? I thought you said you were
storing full text in the Memo field.

A string variable can hold approximately 2 billion characters (2^31), so you
shouldn't have any problem as long as the Memo field does contain text.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"Tony_VBACoder" <(E-Mail Removed)> wrote in message
news:61E7C03A-FA33-4307-BDB9-(E-Mail Removed)...
> Dirk and Doug, thanks for the assistance. I had the looping routine
> written,
> but was concerned about string variables being truncated because memo
> fields
> can be virtually anything. This brings me to Dirk's suggestion of using
> the
> Instr function. Won't Access "choke" using Instr on a memo field because
> a
> memo field could be virtually anything?
>
> Also, in my situation, Instr, will not work, because I have to find many
> instances of various values and then whatever follows that value. For
> instance, I have to search for FirstName and then whatever is after
> FirstName, to come up with the person's first name. But yes, that was a
> great suggestion.
>
> "Dirk Goldgar" wrote:
>
>> "Tony_VBACoder" <(E-Mail Removed)> wrote in
>> message news:4D69D3F6-3718-4CC2-8E23-(E-Mail Removed)
>> > I have a situation where we scan in documents and store the full text
>> > of the document in a Memo field. Now, I need to write a VBA looping
>> > routine that will loop through each character of the Memo field
>> > looking for various pieces of information.
>> >
>> > What is the best method for doing this? Are there limitations on
>> > trying to read the entire Memo field into a string variable, or some
>> > other variable type?

>>
>> You can assign the field's value to a string variable, and use code like
>> this:
>>
>> Dim strText As STring
>> Dim I As Long
>>
>> strText = Nz(Me!MyMemoField, "")
>>
>> For I = 1 To Len(strText)
>>
>> If Mid(strText, I, 9) = "Something" Then
>> ' found "Something" ...
>> End If
>>
>> Next I
>>
>> However, if you're looking for specific strings, it will be a *lot*
>> faster to use the InStr() function to locate them:
>>
>> Dim strText As STring
>> Dim I As Long
>>
>> strText = Nz(Me!MyMemoField, "")
>>
>> I = InStr(strText, "Something")
>> If I > 0 Then
>> ' found "Something" ...
>> End If
>>
>> --
>> Dirk Goldgar, MS Access MVP
>> www.datagnostics.com
>>
>> (please reply to the newsgroup)
>>
>>
>>



 
Reply With Quote
 
Dirk Goldgar
Guest
Posts: n/a
 
      5th Apr 2006
"Tony_VBACoder" <(E-Mail Removed)> wrote in
message news:61E7C03A-FA33-4307-BDB9-(E-Mail Removed)
> Dirk and Doug, thanks for the assistance. I had the looping routine
> written, but was concerned about string variables being truncated
> because memo fields can be virtually anything. This brings me to
> Dirk's suggestion of using the Instr function. Won't Access "choke"
> using Instr on a memo field because a memo field could be virtually
> anything?


I don't follow you. A memo field will always contain text, though it
might be in "rich text format".

> Also, in my situation, Instr, will not work, because I have to find
> many instances of various values and then whatever follows that
> value. For instance, I have to search for FirstName and then
> whatever is after FirstName, to come up with the person's first name.
> But yes, that was a great suggestion.


I don't see the problem. You can search repeatedly for the same or
different strings, and once you've found the occurrence you want, you
can scan forward from that position for a delimiting character of some
sort.

Note that the InStr() function has an optional <Start> argument, which
can be used to specify the starting point for the search, within the
text being searched. That lets you keep searching for new occurrences
until there aren't any more, and it lets you search for (e.g.) the end
of the first name, once you've found the word "FirstName".

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
user error? Access 2000 file on network memo field keeps losing data and corrupting table jwflutterby@gmail.com Microsoft Access 6 5th Dec 2006 12:31 AM
Access 2000 - How to Generate Multiline Strings in a Memo field... =?Utf-8?B?SmFtZGVl?= Microsoft Access Form Coding 1 2nd Dec 2005 08:41 PM
Print a Memo Field in Access 2000 Report =?Utf-8?B?QXVkaXRJQQ==?= Microsoft Access Reports 5 19th Oct 2004 12:02 AM
Exporting Memo field in Access 2000 (quick HELP needed) KT Microsoft Access 1 29th Jun 2004 08:17 PM
Access 2000 Multitable query memo field garbage jkonkal Microsoft Access Queries 0 29th Jan 2004 03:36 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:13 PM.