dbTalk Databases Forums  

Memo field Instr function

comp.databases.ms-access comp.databases.ms-access


Discuss Memo field Instr function in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
bobdydd
 
Posts: n/a

Default Memo field Instr function - 02-04-2011 , 06:54 AM






Hi

I have a Memo field with customers names and addresses
I would like to write code to make the following happen


MR JOE SAMPLE
1 THE HIGH STREET
BIDCHESTER
SOMERSET
TN8 6TY

MR JOE SAMPLE<br>
1 THE HIGH STREET<br>
BIDCHESTER<br>
SOMERSET<br>
TN8 6TY<br>

I think it is the Instr function but I am getting
nowhere fast

Can anyone help. Thanks

Reply With Quote
  #2  
Old   
Salad
 
Posts: n/a

Default Re: Memo field Instr function - 02-04-2011 , 09:49 AM






bobdydd wrote:
Quote:
Hi

I have a Memo field with customers names and addresses
I would like to write code to make the following happen


MR JOE SAMPLE
1 THE HIGH STREET
BIDCHESTER
SOMERSET
TN8 6TY

MR JOE SAMPLE<br
1 THE HIGH STREET<br
BIDCHESTER<br
SOMERSET<br
TN8 6TY<br

I think it is the Instr function but I am getting
nowhere fast

Can anyone help. Thanks
This sub reads a memo field (M) in Table1 and parses it out
Private Sub MemoSplit()
Dim intFor As Integer
Dim ar() As String
Dim r As Recordset
Set r = CurrentDb.OpenRecordset("Table1")

'split lines up
ar = Split(r!M, vbNewLine) 'M is a memo field.

For intFor = LBound(ar) To UBound(ar)
'prints out each line in memo
MsgBox ar(intFor)
Next

r.Close
Set r = Nothing

End Sub

This sub adds a value to memo field M in Table1
Private Sub MemoAdd()
Dim s As String
Dim r As Recordset

Set r = CurrentDb.OpenRecordset("Table1")

s = "This" & vbNewLine & "Is" & vbNewLine & "A" & _
vbNewLine & "6" & vbNewLine & "Line" & vbNewLine & "Memo"

r.AddNew
r!M = s
r.Update

MsgBox "Added " & s

r.Close
Set r = Nothing
End Sub

Reply With Quote
  #3  
Old   
John W. Vinson
 
Posts: n/a

Default Re: Memo field Instr function - 02-04-2011 , 11:02 AM



On Fri, 4 Feb 2011 04:54:47 -0800 (PST), bobdydd
<reallyuseful2004 (AT) yahoo (DOT) co.uk> wrote:

Quote:
Hi

I have a Memo field with customers names and addresses
I would like to write code to make the following happen


MR JOE SAMPLE
1 THE HIGH STREET
BIDCHESTER
SOMERSET
TN8 6TY

MR JOE SAMPLE<br
1 THE HIGH STREET<br
BIDCHESTER<br
SOMERSET<br
TN8 6TY<br

I think it is the Instr function but I am getting
nowhere fast

Can anyone help. Thanks
You don't actually need InStr, just Replace:

UPDATE table
SET memofield = Replace([memofield], Chr(13) & Chr(10), "<br>")

will find all instances of a carriage-return new-line pair and replace them
with the text string <br>. Use

"<br>" & Chr(13) & Chr(10)

if you want to retain both the html tag and the actual new-line pair.
--

John W. Vinson [MVP]
Microsoft's replacements for these newsgroups:
http://social.msdn.microsoft.com/For...-US/accessdev/
http://social.answers.microsoft.com/.../en-US/addbuz/
and see also http://www.utteraccess.com

Reply With Quote
  #4  
Old   
elg
 
Posts: n/a

Default Re: Memo field Instr function - 02-05-2011 , 09:14 AM



On Feb 4, 5:02*pm, John W. Vinson <jvinson (AT) STOP_SPAM (DOT) WysardOfInfo.com>
wrote:
Quote:
On Fri, 4 Feb 2011 04:54:47 -0800 (PST), bobdydd



reallyuseful2... (AT) yahoo (DOT) co.uk> wrote:
Hi

I have a Memo field with customers names and addresses
I would like to write code to make the following happen

MR JOE SAMPLE
1 THE HIGH STREET
BIDCHESTER
SOMERSET
TN8 6TY

MR JOE SAMPLE<br
1 THE HIGH STREET<br
BIDCHESTER<br
SOMERSET<br
TN8 6TY<br

I think it is the Instr function but I am getting
nowhere fast

Can anyone help. Thanks

You don't actually need InStr, just Replace:

UPDATE table
SET memofield = Replace([memofield], Chr(13) & Chr(10), "<br>")

will find all instances of a carriage-return new-line pair and replace them
with the text string <br>. Use

"<br>" & Chr(13) & Chr(10)

if you want to retain both the html tag and the actual new-line pair.
--

* * * * * * *John W. Vinson [MVP]
*Microsoft's replacements for these newsgroups:
*http://social.msdn.microsoft.com/For...-US/accessdev/
*http://social.answers.microsoft.com/.../en-US/addbuz/
*and see alsohttp://www.utteraccess.com
Memo fields have been a pain since Clipper87 days. In my opinion they
cause more problems than they solve. I avoid them except in mayge
setup or standing data tables. I never include them into the main
tables which will contain thousands or records.

Reply With Quote
  #5  
Old   
bobdydd
 
Posts: n/a

Default Re: Memo field Instr function - 02-11-2011 , 02:44 PM



Quote:
* * * * * * *John W. Vinson [MVP]
Thanks John. That works a treat...Many Thanks

Reply With Quote
Reply




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.