access coopy paste only text into textbox (1 Viewer)

megatronixs

Registered User.
Local time
Today, 14:09
Joined
Aug 17, 2012
Messages
719
Hi all,

I have the below code to copy from a textbox into another one but only as text (no formatting). I need to use the text for an invitation in Outlook as the invitation will not work with rich text format in the body created with vba.
Code:
Me.acctions.SetFocus
    DoCmd.RunCommand acCmdCopy
Me.text_for_email.SetFocus
DoCmd.RunCommand acCmdPasteSpecial
    oMail.Body = Me.text_for_email

If I copy it in memory from the field "acctions" then I can paste it in the invitation and it maintains the format (strange thing), but with vba it just adds the tags with text and it becomes messy.

Any ideas to paste special text without getting the little dialog box to chose Tex from to continue?

Greetings.
 

isladogs

MVP / VIP
Local time
Today, 13:09
Joined
Jan 14, 2017
Messages
18,235
The PlainText function converts rich text to .... plain text

Code:
oMail.Body = PlainText(Me.text_for_email)

Additional info from Access Help:
Sorry about the formatting - the forum has converted rich text to plain text ,,,:D

Strips the rich text formatting from a string and returns an unformatted text string.
Version Information
Version Added: Access 2007

Syntax
expression.PlainText(RichText, Length)

expression A variable that represents an Application object.

Parameters

Name Required/Optional Data Type Description
RichText Required Variant The rich text string that you want to remove the formatting of.
Length Optional Variant The number of character to return.

Return Value
String
 
Last edited:

megatronixs

Registered User.
Local time
Today, 14:09
Joined
Aug 17, 2012
Messages
719
Hi Ridders,

I tried that one, but it puts all into one line (with spaces).
If I have like below:
point 1
point 2
point 3

It will put it like this:
point 1 point 2 point 3

I can't use it like that. the invitation needs to have the points from the meeting and things will be hard to read that way.

If I copy the text from the text box with all the formatting and paste it in the email, it looks great, but with vba I can't do it :(

Greetings.
 

Orthodox Dave

Home Developer
Local time
Today, 13:09
Joined
Apr 13, 2017
Messages
218
Hi Megatronixs,

I've done this successfully in my database using rich text in the Outlook email.

Firstly, I have a table for Mail Text with fields in Long Text with RTF formatting. These can be populated just like a Word document (new line, bold, italic etc). When this field is copied to a string variable, Access adds in all the HTML formatting stuff to the string. Then making the Body Format Rich Text and using .HTMLBody (rather than .Body) the formatting comes right into the email.

Code:
Dim BodyText As String, TextBodyPt1 As String

TextBodyPt1 = [the contents of the RTF field]

BodyText = "<FONT FACE='arial'>" & Salutation
BodyText = BodyText & TextBodyPt1

 Set objMail = olApp.CreateItem(olMailItem)
 
With objMail
 'Set body format to Rich Text
 .BodyFormat = olFormatRichText
  
.To = ToAddress
.Subject = SubjectText
.HTMLBody = BodyText
.CC = CCs
.Display 
End With

That's a highly abbreviated version of a disgracefully long sub, but I left in the relevant bits for your purposes.
 

megatronixs

Registered User.
Local time
Today, 14:09
Joined
Aug 17, 2012
Messages
719
hi all,

I actually solved this by combining both of your suggestions :)

Greetings.
 

Users who are viewing this thread

Top Bottom