Solved

Memo field, RTF, paste only the text

Posted on 2013-05-26
8
530 Views
Last Modified: 2013-05-27
Experts,

I have a memo field formatted as RTF.
I have this memo field on a form that opens as modal.
I want to paste the text as plain text (and then format it)
I hit paste special<Text and it pastes as RTF.  

How can I paste the text as plain?  
I do not want to paste to notepad and then paste into the memo field (too many steps).  

thank you.
0
Comment
Question by:pdvsa
  • 4
  • 3
8 Comments
 
LVL 29

Assisted Solution

by:IrogSinta
IrogSinta earned 150 total points
ID: 39197942
Use the PlainText function:
=PlainText(NameOfMemoField)
0
 

Author Comment

by:pdvsa
ID: 39197990
OK but how do I use this?  I mean I want to be able to use it possibly as a rt click or some other simple way.
0
 
LVL 20

Expert Comment

by:GrahamMandeno
ID: 39198714
As far as I know, there is no way in the UI to "Copy as Plain Text".  However, it can be done through code with a command button.  Copy the following code and paste it into a new standard module:
Option Compare Database
Option Explicit

Private Declare Function GlobalUnlock _
  Lib "kernel32" ( _
    ByVal hMem As Long _
  ) As Long

Private Declare Function GlobalLock _
  Lib "kernel32" ( _
    ByVal hMem As Long _
  ) As Long

Private Declare Function GlobalAlloc _
  Lib "kernel32" ( _
    ByVal wFlags As Long, _
    ByVal dwBytes As Long _
  ) As Long

Private Declare Function GlobalSize _
  Lib "kernel32" ( _
    ByVal hMem As Long _
  ) As Long

Private Declare Function lstrcpy _
  Lib "kernel32" ( _
    ByVal lpString1 As Any, _
    ByVal lpString2 As Any _
  ) As Long

Private Declare Function CloseClipboard _
  Lib "user32" ( _
  ) As Long

Private Declare Function OpenClipboard _
  Lib "user32" ( _
    ByVal hWnd As Long _
  ) As Long

Private Declare Function EmptyClipboard _
  Lib "user32" ( _
  ) As Long

Private Declare Function GetClipboardData _
  Lib "user32" ( _
    ByVal wFormat As Long _
  ) As Long

Private Declare Function SetClipboardData _
  Lib "user32" ( _
    ByVal wFormat As Long, _
    ByVal hMem As Long _
  ) As Long

Private Const GHND = &H42
Private Const CF_TEXT = 1

Public Function ClipBoard_SetText(strCopyString As String) As Boolean
  Dim hGlobalMemory As Long
  Dim lpGlobalMemory As Long
  Dim hClipMemory As Long

  ' Allocate moveable global memory.
  hGlobalMemory = GlobalAlloc(GHND, Len(strCopyString) + 1)

  ' Lock the block to get a far pointer to this memory.
  lpGlobalMemory = GlobalLock(hGlobalMemory)

  ' Copy the string to this global memory.
  lpGlobalMemory = lstrcpy(lpGlobalMemory, strCopyString)

  ' Unlock the memory and then copy to the clipboard
  If GlobalUnlock(hGlobalMemory) = 0 Then
    If OpenClipboard(0&) <> 0 Then
      Call EmptyClipboard
      hClipMemory = SetClipboardData(CF_TEXT, hGlobalMemory)
      ClipBoard_SetText = CBool(CloseClipboard)
    End If
  End If
End Function

Public Function ClipBoard_GetText() As String
  Dim hClipMemory As Long
  Dim lpClipMemory As Long
  Dim strCBText As String
  Dim lngSize As Long
  If OpenClipboard(0&) <> 0 Then
    ' Obtain the handle to the global memory
    ' block that is referencing the text.
    hClipMemory = GetClipboardData(CF_TEXT)
    If hClipMemory <> 0 Then
      ' Lock Clipboard memory so we can reference
      ' the actual data string.
      lpClipMemory = GlobalLock(hClipMemory)
      If lpClipMemory <> 0 Then
        lngSize = GlobalSize(lpClipMemory)
        strCBText = SPACE$(lngSize)
        Call lstrcpy(strCBText, lpClipMemory)
        Call GlobalUnlock(hClipMemory)
        ' Peel off the null terminating character.
        strCBText = Left(strCBText, InStr(strCBText, vbNullChar) - 1)
      End If
    End If
    Call CloseClipboard
  End If
  ClipBoard_GetText = strCBText
End Function

Open in new window

Save the module as "mdlClipBoard"

Now, add a command button to your form with the caption "Copy as Plain Text" (or whatever else you like).  Name the button cmdCopyPlainText and assign it this event procedure:
Private Sub cmdCopyPlainText_Click()
On Error Resume Next
    ClipBoard_SetText Application.PlainText(Screen.PreviousControl.Value)
    If Err Then
        MsgBox "Cannot copy text" & vbCrLf & Err.Description
        Err.Clear
    End If
End Sub

Open in new window

Clicking this button will set the contents of the clipboard to the plain text version of the current control (which has just become the PreviousControl, because you have clicked the command button).

Best wishes,
Graham Mandeno [Access MVP 1996-2013]
0
 

Author Comment

by:pdvsa
ID: 39199656
Graham:  thank you for the response.  

I have to ask a follow up as I am not certain if I am using it as I should.
I have made the module and saved it.
I put a button on the form and named it as instructed and pasted the open form code as well.

to use it I open the form, go to ms word and copy something, go back to the form, hit the command button and the text is not pasted.  

I see the command button is named Copy text and I am under the assumption the button is used to Paste the text.    

I am not sure if I am suppose to initially paste the RTF text into the field with control V and then select it again, hit the command button to copy and and then use control V to repaste as plain text.
Please let me know what to do next.
==>this method seems to remove the RTF though.  

thank you once again....
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 20

Expert Comment

by:GrahamMandeno
ID: 39199709
I understood that you wanted to copy from the memo textbox as plain text so that you could paste the plain text contents somewhere else.  I now see that you want to copy some formatted text from Word, and paste the plain text into your memo textbox.  My apologies for the misunderstanding.

Assign the following code to your command button's Click event:

Me![name of your memo control] = Application.PlainText(ClipBoard_GetText)

The event procedure should contain only this single line.

Good luck :-)
Graham
0
 

Author Comment

by:pdvsa
ID: 39199826
Ok that worked perfectly.   I suppose IrogSinta had essentially the same response but I am not an expert and not sure if they are one in the same.  Not certain if Irog's suggestion was to side step any module.  

Using Irog's method I sorta combined what you had mentioned but used the plaintext:
    Me!txtComments = PlainText(txtComments)
==>however, text was not pasted after copying from word.
0
 
LVL 20

Accepted Solution

by:
GrahamMandeno earned 250 total points
ID: 39199884
Me!txtComments = PlainText(txtComments)

This will simply take the rich text contents of the textbox and replace it with the plain text version.  To get it there from Word, you will need to paste in the textbox and then click the button to remove the formatting.

If you want a one-step method, then use the line I gave you:
Me!txtComments = Application.PlainText(ClipBoard_GetText)

Open in new window


This will take whatever is already in the clipboard (copied from Word), strip the formatting, and place the plain text version in your textbox.

-- Graham
0
 

Author Closing Comment

by:pdvsa
ID: 39199986
I awarded points to both because while IrogSinta had a quick solution that worked great, I did not know how to implement it and Graham taught me how to do just that and by using a module I have one less step.  

thank you both for the help.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now