Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DELETE EMPTY LINES ON MEMO AUTOMATICALLY 3

Status
Not open for further replies.

franksirvent

Programmer
Mar 8, 2002
358
GB
Hi

I have a Memo field which I paste email messages.

I would like that, on exit, to delete all the empty lines within the memo field.

For example:
"this is the first line

this is the second line

etc etc"

I want it to become
"this is the first line
this is the second line
etc etc"

This way the memo field doesn't have nany empty lines and it is obviously easier to read.

Any help is appeciated

thanks in advance

 
You need to identify the characters causing the line breaks. Usually a single line break is caused by Chr(13) & Chr(10). So you could use the after update event of the text box to
Replace([YourField],Chr(13) & Chr(10) & Chr(13) & Chr(10) , Chr(13) & Chr(10) )

Duane
MS Access MVP
Find out how to get great answers faq219-2884.
 
Of course to get rid of lines that have only spaces on them you will need to use regular expressions.

[blue]"Well, once again my friend, we find that science is a two headed beast. One head is nice, it gives us aspirin and other modern conveniences,...but the other head of science is BAD! Oh, beware the other head of science, Arthur; it bites!!" - The Tick[/blue]
 
I don't understand TomThumbKP.
Could you elaborate on that ???

thanks
 
The replace command above will only catch blank lines that have absolutely no content on them. If there is a line that has a space on it and that is the only thing on the lines, then it will not be removed with the Replace command.

[blue]"Well, once again my friend, we find that science is a two headed beast. One head is nice, it gives us aspirin and other modern conveniences,...but the other head of science is BAD! Oh, beware the other head of science, Arthur; it bites!!" - The Tick[/blue]
 
to remove extra spaces you could you something like this.

Dim txtlength1 As Long, txtlength2 As Long
txtlength1 = 0
txtlength2 = 1
Do Until txtlength1 = txtlength2
txtlength2 = Len(txtreplace)
txtreplace = Replace(txtreplace, Space(2), " ")
txtlength1 = Len(txtreplace)
Loop
 
THat would simply take double spaces and turn them into single spaces. The problem is a line with any number of spaces on it.

[blue]"Well, once again my friend, we find that science is a two headed beast. One head is nice, it gives us aspirin and other modern conveniences,...but the other head of science is BAD! Oh, beware the other head of science, Arthur; it bites!!" - The Tick[/blue]
 
like this:

Dim txtlength1 As Long, txtlength2 As Long
txtlength1 = 0
txtlength2 = 1
Do Until txtlength1 = txtlength2
txtlength2 = Len(txtreplace)
txtreplace = Replace(txtreplace, Space(1) & Chr(13) & Chr(10), Chr(13) & Chr(10))
txtreplace = Replace(txtreplace, Space(2), " ")
txtlength1 = Len(txtreplace)
Loop
 
Hi all,
The above code doesn't seem to work.

Here is an example of what I am trying to achieve.
below is an email message which I copy from an email and paste to an Access memo field. On exit from this field, I want to reformat the text.
Below on the line with 'o request' there are 3 blank lines.
These lines are blank and I would like them to be deleted when the memo field is reformatted (using the code I need)
I want to do the same thing with almost any blank line...

I hope that is a bit clearer. Sometimes it is hard to write down the ideas.

thanks

" Mon--Tue--Wed--Thr--Fri
week 25 Out Out Out Out Out

Rates, charges and fees are based on todays' tariffs and rates of
exchange and are subject to change without notice; any proposal Terms & Conditions of Service which are available on request



"Alc FS Frank Sirvent" <frank.sirvent@ONO.com>
Sent by: frank.sirvent@ONO.com
06/15/2004 05:40 AM

To"
--------------------------------------------------------
THE ABOVE MESSAGE WOULD LOOK LIKE THEN:
" Mon--Tue--Wed--Thr--Fri
week 25 Out Out Out Out Out
Rates, charges and fees are based on todays' tariffs and rates of
exchange and are subject to change without notice; any proposal Terms & Conditions of Service which are available on request
"Alc FS Frank Sirvent" <frank.sirvent@ONO.com>
Sent by: frank.sirvent@ONO.com
06/15/2004 05:40 AM
To
 
what does the code do that doesn't work? an error?
 
it only loops once (i am not sure if that's what it should do...)

because txtlength1=txtlength2 on the first loop, it finishes the loop and ends the changes...

nothing seems to happen....

txtlength1 = 0
txtlength2 = 1
Do Until txtlength1 = txtlength2
txtlength2 = Len(txtreplace)
txtreplace = Replace(txtreplace, Space(1) & Chr(13) & Chr(10), Chr(13) & Chr(10))
txtreplace = Replace(txtreplace, Space(2), " ")
txtlength1 = Len(txtreplace)
Loop

 
try it like this with just removing the extra CR and new line. if you want i can e-mail you a copy of what i have working.

Dim txtlength1 As Long, txtlength2 As Long
txtlength1 = 0
txtlength2 = 1
Do Until txtlength1 = txtlength2
txtlength2 = Len(YourField)
YourField = Replace([YourField], Chr(13) & Chr(10) & Chr(13) & Chr(10), Chr(13) & Chr(10))
txtlength1 = Len(YourField)
Loop
 
You may consider replacing this:
YourField = Replace([YourField], Chr(13) & Chr(10) & Chr(13) & Chr(10), Chr(13) & Chr(10))
By this:
YourField = Replace(Trim([YourField]), vbCrLf & vbCrLf, vbCrLf)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Oops, posted to fast.
What about something like this ?
tmpArr = Split([memoField], vbCrLf)
tmpStr = ""
For i = 0 To UBound(tmpArr)
t = Trim(tmpArr(i))
If Len(t) > 0 Then tmpStr = tmpStr & t & vbCrLf
Next i
[memoField] = tmpStr

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top