none
MS Access Long Text (Rich Text) field to Rich Text Box RRS feed

  • Question

  • Hey!

    So I have been searching for an answer to this question for the past three hours and have found a lot of examples but nothing that addresses my exact issue.

    I have some rich text stored in a "Long Text" field in MS Access 2013 that i am trying to import into a Rich Text Box in Visual Studio 2010 Express (visual basic).  I can successfully pull data from the table  in general so i know that that's not an issue.  And I can run RichTextBox1.Text = selectedRow(0)(7) which will display <div>This is a test.</div> in the Rich Text Box when run.  However, if I change the line to RichTextBox1.Rtf = selectedRow(0)(7) in order to display the text as formatted text, it triggers a run time error: File Format is not valid.

    What am i missing?  Shouldn't this be enough to display the formatted text?

    Thanks

    Sunday, October 27, 2013 5:03 AM

Answers

  • So i guess my next question would be:  assuming my end goal is to allow users to edit text within the form view (with similar functionally  to the text box im writing this reply in, i.e. basic formatting).  What is the best way to allow the user to edit the text, store it in a access database, and then upon completion, export to a MS Word file, all the while preserving the formatting?  I guess i assumed the Rich Text in Access is the same as Rich Text in VB is the same as Rich Text in a Word document.

    If you save the RichTextBox RTF property to the database and then retrieve it into the RichTextBox RTF property, then any formatting in the original text will be preserved - it's part of the RTF.  If you save the Text property into the database and retrieve it, then you will have plain text.

    The field in the database would be string - it doesn't care what the string looks like. But make sure it is not altered in any way at all, as that will destroy the RTF structure that the RichTextBox expects to see in that RTF property.

    • Marked as answer by benw301 Monday, October 28, 2013 2:13 AM
    Sunday, October 27, 2013 9:47 PM

All replies

  • So I have been searching for an answer to this question for the past three hours and have found a lot of examples but nothing that addresses my exact issue.

    I have some rich text stored in a "Long Text" field in MS Access 2013 that i am trying to import into a Rich Text Box in Visual Studio 2010 Express (visual basic).  I can successfully pull data from the table  in general so i know that that's not an issue.  And I can run RichTextBox1.Text = selectedRow(0)(7) which will display <div>This is a test.</div> in the Rich Text Box when run.  However, if I change the line to RichTextBox1.Rtf = selectedRow(0)(7) in order to display the text as formatted text, it triggers a run time error: File Format is not valid.

    What am i missing?  Shouldn't this be enough to display the formatted text?

    Text that you set to the RTF property of the rich text box should be RTF text.  The load usually just fails quietly when it sees an error in the formatting, but I guess in your case it is not seeing the RTF header that it expects, so it fails with an error.   Your text should look something like

    {\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset204{\*\fname Arial;}Arial CYR;}
    {\f1\fswiss\fcharset0 Arial;}} ... \par
    }

    Sunday, October 27, 2013 7:31 AM
  • Thanks Acamar,

    So i guess my next question would be:  assuming my end goal is to allow users to edit text within the form view (with similar functionally  to the text box im writing this reply in, i.e. basic formatting).  What is the best way to allow the user to edit the text, store it in a access database, and then upon completion, export to a MS Word file, all the while preserving the formatting?  I guess i assumed the Rich Text in Access is the same as Rich Text in VB is the same as Rich Text in a Word document.

    Thanks!

    Sunday, October 27, 2013 8:14 PM
  • So i guess my next question would be:  assuming my end goal is to allow users to edit text within the form view (with similar functionally  to the text box im writing this reply in, i.e. basic formatting).  What is the best way to allow the user to edit the text, store it in a access database, and then upon completion, export to a MS Word file, all the while preserving the formatting?  I guess i assumed the Rich Text in Access is the same as Rich Text in VB is the same as Rich Text in a Word document.

    If you save the RichTextBox RTF property to the database and then retrieve it into the RichTextBox RTF property, then any formatting in the original text will be preserved - it's part of the RTF.  If you save the Text property into the database and retrieve it, then you will have plain text.

    The field in the database would be string - it doesn't care what the string looks like. But make sure it is not altered in any way at all, as that will destroy the RTF structure that the RichTextBox expects to see in that RTF property.

    • Marked as answer by benw301 Monday, October 28, 2013 2:13 AM
    Sunday, October 27, 2013 9:47 PM
  • So i guess my next question would be:  assuming my end goal is to allow users to edit text within the form view (with similar functionally  to the text box im writing this reply in, i.e. basic formatting).  What is the best way to allow the user to edit the text, store it in a access database, and then upon completion, export to a MS Word file, all the while preserving the formatting?  I guess i assumed the Rich Text in Access is the same as Rich Text in VB is the same as Rich Text in a Word document.

    If you save the RichTextBox RTF property to the database and then retrieve it into the RichTextBox RTF property, then any formatting in the original text will be preserved - it's part of the RTF.  If you save the Text property into the database and retrieve it, then you will have plain text.

    The field in the database would be string - it doesn't care what the string looks like. But make sure it is not altered in any way at all, as that will destroy the RTF structure that the RichTextBox expects to see in that RTF property.

    Makes sense, thanks for your help!

    Monday, October 28, 2013 2:14 AM