Solved Paste plain text into a rich text field (1 Viewer)

zelarra821

Registered User.
Local time
Today, 23:26
Joined
Jan 14, 2019
Messages
813
Hello. I wanted to know if it is possible to paste plain text into a rich text field.
 

zelarra821

Registered User.
Local time
Today, 23:26
Joined
Jan 14, 2019
Messages
813
In the table, I have rich text enabled. Now, if I copy text from the internet, it pastes it with the internet format, and I don't want that, I want to know if it's possible to have a button to paste only the plain text, as it exists in Word or Excel.
 

jdraw

Super Moderator
Staff member
Local time
Today, 17:26
Joined
Jan 23, 2006
Messages
15,379
You could review Similar Threads at the bottom of the page for possible approaches.
 

zelarra821

Registered User.
Local time
Today, 23:26
Joined
Jan 14, 2019
Messages
813
There's nothing interesting for me. It doesn't solve my problem
 

jdraw

Super Moderator
Staff member
Local time
Today, 17:26
Joined
Jan 23, 2006
Messages
15,379
One option, make the field involved plain text.
 

zelarra821

Registered User.
Local time
Today, 23:26
Joined
Jan 14, 2019
Messages
813
It's an option, but I want a rich field in which I can paste rich text or plain text when I want
 

ebs17

Well-known member
Local time
Today, 23:26
Joined
Feb 7, 2020
Messages
1,949
plain text into a rich text field
I tried it: Yes.

Table and button for input: This is not a practical combination. What are you doing there?

Access RichText is implemented via HTML. There is also a PlainText method that converts RichText to PlainText. However, this will not work for normal HTML code from the Internet. Perhaps your question is how to get plain text out of HTML (so you have something to copy). But you didn't put it that way.
 

zelarra821

Registered User.
Local time
Today, 23:26
Joined
Jan 14, 2019
Messages
813
I don't know if I'm sure I understand you. What I want is to copy from the Internet and not copy the format, but have the rich text activated in case I want to format any field.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 17:26
Joined
May 21, 2018
Messages
8,533
Add a button next to your field.
Code:
Private Sub cmdChange_Click()
  'Where RT is the name of the Richtext field
  Me.RT = Application.PlainText(Me.RT)
End Sub

This will not happen on the paste, but would allow you to change.
You cannot do this in the controls before update without asking the user to confirm. Since, afterwards if you add your own updates it will override.
 

zelarra821

Registered User.
Local time
Today, 23:26
Joined
Jan 14, 2019
Messages
813
Thank you very much for the contribution. One question, let's see how I put it. Can I work in VBA with the copied text? If it were possible to rescue it from the "clipboard", I would add it to a string, which would pass through the Application.PlainText function, saving this last value in another variable, which would be the one that would be saved in the "clipboard".
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 17:26
Joined
May 21, 2018
Messages
8,533
You can repaste it back into the control if it is still in the clipboard. If you want to save the original text then you need another rich text field to store the original.
 

Attachments

  • RichTextConvert.accdb
    1.2 MB · Views: 77

Pat Hartman

Super Moderator
Staff member
Local time
Today, 17:26
Joined
Feb 19, 2002
Messages
43,301
When I want to strip formatting from text I copy, I paste it into NotePad and then copy and paste from there. Copy/Paste is not your typical method of transferring data from one place to another when working with RDBMS'. It is an Excel standby though.
 

zelarra821

Registered User.
Local time
Today, 23:26
Joined
Jan 14, 2019
Messages
813

Attachments

  • RichTextConvert.accdb
    1.2 MB · Views: 73

zelarra821

Registered User.
Local time
Today, 23:26
Joined
Jan 14, 2019
Messages
813
For the example, MsgBox strContents is missing. But the idea is that, once it is retrieved from the clipboard and the formatting is removed, copy it back to the clipboard
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 17:26
Joined
May 21, 2018
Messages
8,533
Works for me. Will paste the clipboard as plaintext. Or the user can just paste and convert.
Code:
Private Sub cmdClip_Click()
   Me.RT = Application.PlainText(Clipboard)
End Sub
Function Clipboard(Optional StoreText As String) As String
'PURPOSE: Read/Write to Clipboard
'Source: ExcelHero.com (Daniel Ferry)

Dim x As Variant
'Store as variant for 64-bit VBA support
  x = StoreText
'Create HTMLFile Object
  With CreateObject("htmlfile")
    With .parentWindow.clipboardData
      Select Case True
        Case Len(StoreText)
          'Write to the clipboard
            .setData "text", x
        Case Else
          'Read from the clipboard (no variable passed through)
            Clipboard = .GetData("text")
      End Select
    End With
  End With
End Function

Private Sub cmdConvert_Click()
  Me.RT = Application.PlainText(Nz(RT, ""))
End Sub
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 17:26
Joined
May 21, 2018
Messages
8,533
Update
 

Attachments

  • RichTextConvert (1).accdb
    1.2 MB · Views: 66

zelarra821

Registered User.
Local time
Today, 23:26
Joined
Jan 14, 2019
Messages
813
I do not know how it works. I don't understand the code. Also, I add breakpoints to watch the code and it doesn't work either.
 

zelarra821

Registered User.
Local time
Today, 23:26
Joined
Jan 14, 2019
Messages
813
I have already solved. I was in design mode and I had to copy everything to another database
 

Users who are viewing this thread

Top Bottom