We help IT Professionals succeed at work.

How to I read text a text box using code in another form?

pcalabria
pcalabria asked
on
147 Views
Last Modified: 2017-04-26
I have a text box which has several lines of text.  Each line was created using code and the vbcrlf character.
Example:

strMyExample="Line Number One" & vbcrlf & "line Number two" & vbcrlf & "line Number three" & vbcrlf
Forms!frmAutoQuote.MyExample=strMyExample

Now, from code in another module, I want to create an HTML email using the text in the textbox.
I use the code strMyText="<table><tr><td>" & Forms!frmAutoQuote.MyExample & "</td></tr></table>

When I use the text to print in the email all the carriage returns are lost, and the code prints as if it paragraph form.
Comment
Watch Question

Anders Ebro (Microsoft MVP)Microsoft Developer
CERTIFIED EXPERT

Commented:
Use the HTMLEncode function.
strMyText="<table><tr><td>" & HtmlEncode(Forms!frmAutoQuote.MyExample) & "</td></tr></table>

Open in new window


To play around, and get an idea of what it does, you can use:
mgsbox HTMLEncode(Forms!frmAutoQuote.MyExample)

Open in new window

CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2019

Commented:
HTML does not recognise white space formatting unless inside <pre> tags.
If you want line breaks you muse use the <br/> tag in addition to (or instead of) the carriage return. The latter will be ignored if it is present. The reason for including it would be if you want to view the generated source after the fact - it makes for easier to read formatting - in HTML view though the CR is not rendered.

Author

Commented:
Still Stuck

@Anders  The HtmlEncode encode function does not seem to work.  Perhaps because I'm using Access 2k?

@Julian  I didn't understand your message.  To create the text in my text box I am not using HTML.  Line breaks were generated, as per my example, using vbCRLF.   Now I want the text to appear in an HTML email.  I suspect the problem is that the HTML email is ignoring the vbCRLF which is probably chr(10) & chr(13)... Are you suggesting I write text to the textbox using vbcrlf & "<br/> at the end of each line?" ?????  I'll give that a try but then where doe the <pre> go?
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2019

Commented:
I suspect the problem is that the HTML email is ignoring the vbCRLF
Please read my post again

CR are not rendered in HTML - you need to use the <br/> tag.
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2019

Commented:
I'll give that a try but then where doe the <pre> go?

The <pre> does not go anywhere - I was trying to explain that the only time CR chars are rendered is if they are inside <pre> tags (pre formatted tags) otherwise HTML ignores them.

For your purposes all you need is <br/>

The CRLF is optional - it won't hurt to put it in but it won't be rendered.
CERTIFIED EXPERT
Expert of the Year 2008
Top Expert 2008
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks to both of you for helping.

Hielo's solution was exactly what I needed and worked perfectly.
Anders Ebro (Microsoft MVP)Microsoft Developer
CERTIFIED EXPERT

Commented:
Yes, HTMLEncode is 2007+. But I see you got it working :)

Author

Commented:
@Anders - Yes, and thank you.  We have started migrating to A2016, I'm sure this will someday help!

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.