How to get formatted text out of the Access database into a Word Bookmark

Q:  Dawn Crosier writes:  I read through your “Access 2007 VBA For Data-Centric Microsoft Office Applications” and have questions about how to get formatted text out of the Access database into a Word Bookmark without bringing all the HTML code.

A:  I did some experimentation, using my Rich Text Demo sample database from Access Archon #157.  I found that the plain text could be extracted from rich text in an Access control using the wdFormatPlainText named constant.  Here is code for a command button Click event that puts the plain text from a Rich Text control into a new Word document (it could also be written to a bookmark or doc property):

Private Sub cmdPastePlainTexttoWord_Click()
 
On Error GoTo ErrorHandler
 
   Dim strRichText As String
   Dim appWord As Word.Application
   Dim doc As Word.Document
   
   Set appWord = GetObject(, “Word.Application”)
   Set doc = appWord.Documents.Add
   Me![txtLetterBody].SetFocus
   DoCmd.RunCommand acCmdCopy
   doc.Select
   appWord.Selection.PasteAndFormat (wdFormatPlainText)
   
ErrorHandlerExit:
   Exit Sub
 
ErrorHandler:
   If Err = 429 Then
      ‘Word is not running; open Word with CreateObject
      Set appWord = CreateObject(“Word.Application”)
      Resume Next
   Else
      MsgBox “Error No: ” & Err.Number & “; Description: ” _
         & Err.Description
      Resume ErrorHandlerExit
   End If
 
End Sub