Solved

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

Posted on 2009-07-08
8
1,077 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
  • 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
 

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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
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…

920 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

16 Experts available now in Live!

Get 1:1 Help Now