Solved

Copy data from ClipBoard into Rich Text Memo Field in MS Access 2007

Posted on 2009-07-08
8
1,130 Views
Last Modified: 2013-11-27
We are trying to paste Rich Text from a WORD document programatically into a memo field in MS Access.  The cut and paste works fine but when we use dataobject, the rich text formatting appears to be stripped.  Do we need to explcitly define the RTF format when the data is pasted?  If so, how?  Also, we assume once this function pastes correctly we will be able to paste RTF direclty into a memo field that is set up for RTF.
 
We have 1 button (PasteFromCB) and 1 unbound text box(RTFTextBox) set to RTF format on a form.  Here is the code behind the button:
 
Private Sub PasteFromCB_Click()
On Error GoTo Err_PasteFromCB_Click
 
Dim MyData As DataObject
 
    Set MyData = New DataObject
   
    'check to see if pasted clipboard info is text
    MyData.GetFromClipboard
    If MyData.GetFormat(1) = False Then
        MsgBox ("Data is not text.  Try again.")
        GoTo Exit_PasteFromCB_Click
    End If
   
    'Yes, clipboard is text.  Continue.
    Me!RTFTextBox = MyData.GetText
 
Exit_PasteFromCB_Click:
    Exit Sub
   
Err_PasteFromCB_Click:
    MsgBox Err.Description
    Resume Exit_PasteFromCB_Click
 
End Sub
0
Comment
Question by:Savtek_com
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 1

Expert Comment

by:VijayprakashM
ID: 24806094
Get the clip board data to a simple text

Further what you need to do to get the text data into rich text memo field in ms access 2007 is use Xbasic
Using Xbasic you can play with RTF object,Xbasic can manipulate data in variables and in RTF memo fields.Create a temporary RTF object you can use RTF.CREATE() method.

Please go through the link below for step by step process

http://support.alphasoftware.com/alphafivehelpv8/Xbasic/Working_with_RTF_Data.htm
0
 

Author Comment

by:Savtek_com
ID: 24806546
Thanks for the suggestion but our project requires that we stay in Access 2007.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 24807793
Savtek_com,

This is very difficult to do.

1. <when we use dataobject>
First things first.
What happens if you simply copy and paste from Windows?

2. Stumbling block:
Access 2007 *DOES NOT* true Rich text, it uses HTML formatting.
Word used True Rich Text.
I will assume that this is why your Copy/Paste code does not work properly.

3. In Access 2007 you can format the data once it is in the Database (table), however, you cannot insert RTF or HTML formatted data (Like in my screenshot) into the table directly, and have it display in the Form/Report formatted.

Please remember that the data stored in a database really has no format, it is raw data, you can apply formatting, to make it look a certain way, but the stored data contains no formatting.
This is why this is so tricky.

There are HTML and Rich text controls out there that you can play with. But again, you may need to do a lot of  Filp-Flopping with the Code and character formatting to pull this off.

JeffCoachman

untitled.JPG
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Savtek_com
ID: 24808131
Jeff,
Thanks for the response.  Let me clarify a few things:

1) The problem we are having is not an issue between rtf and html.  Yes, some formatting is not kept after pasting such as tables, etc. but in general it looks pretty good.

2) Using Windows to copy an entire WORD document and then pasting the clipboard into an Access memo field works fine and keeps the formatting.  The problem is if the WORD document is larger than 65000 characters, the data is truncated to this maximum amount.  The formatting looks great but we lose half of our data.

3) We have, however, successfully copied the entire WORD document when it is greater than 65000 characters (ours is 131000) using the code initially submitted but unfortunately all the formatting is stripped from the data.

So, it seems we can either keep the formatting but have a shortened document or keep the entire document but have no formatting.  Selfishly we are trying to do both.

Any further ideas?
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 24809873
Why not just link to the Word Document directly?
0
 

Author Comment

by:Savtek_com
ID: 24810266
Yes, another good idea but we link to Word, excel and pdf documents in this application already and it works extremely well.  For this particular document, they want to view it along with other data that is entered in the same table /memo field without opening up another application, i.e. Word.  And what the client wants...
0
 
LVL 74

Accepted Solution

by:
Jeffrey Coachman earned 500 total points
ID: 24810411
...may not be possible

;-)

Jeff
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 24850584
;-)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

733 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