Solved

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

Posted on 2009-07-08
8
1,102 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
Back Up Your Microsoft Windows Server®

Back up 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.

 

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

777 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