PDA

View Full Version : Test for blank paragraph in a userform textfield



Strongs
01-10-2008, 03:02 PM
Hi everyone and a Happy New Year to you all!

I have a userform that pulls in paragraphs from an enclosing bookmark in a protected document.

The user can then add to, or remove paragraphs and when the form is submitted, the bookmark is updated to reflect the changes.

The paragraphs within the bookmark are numbered, so if the user leaves a blank paragraph at the end of the text within the userform textbox, then an empty paragraph number is appended to the last line in the updated bookmark.

My question is this:

Is there any way to test if the text within the userform textbox contains and empty paragraph and stripping it out before updating the bookmark.

I can do this using the following code, but of course, if the text does not contain an empty paragraph mark, then the last two characters of the updated bookmark are removed.

UpdateBookmark in the code is a user defined function for updating the bookmark.

Sub RemPara()
Dim ref as String
ref = Me.References.Value
ref=Left(ref,Len(ref) - 2)
UpdateBookmark ref
End Sub

Hope you can help

Regards,

TonyJollans
01-11-2008, 05:21 AM
If you simply want to remove trailing new line characters ...


Do While Right$(ref, 2) = vbNewLine
ref = Left$(ref, Len(ref) - 2)
Loop

Strongs
01-11-2008, 08:27 AM
Hi Tony,

Hit the spot! Many thanks for your help.

Regards,

fumei
01-14-2008, 12:49 PM
Nice. Clean and efficient.

TonyJollans
01-14-2008, 12:58 PM
Thanks, Gerry. Strictly speaking the '2' should not be hard coded. It should be len(vbnewline) but I thought that overkill :)

fumei
01-14-2008, 01:03 PM
"but I thought that overkill"

Indeed.


:bubblebat