Solved

Writing RichTextBox to Access in Visual Basic 2008

Posted on 2008-06-18
8
694 Views
Last Modified: 2013-11-26
I am writing a program that allows the user to input formatted text into a rich text box in visual basic 2008. This information is then written to an access database (.mdb format), but the rich text formatting is not written to the database file, it only shows up as plain text.
Public Class NewJob
 
    Private m_cnadonetconnection As New OleDb.OleDbConnection
    Private m_dadataadapter As OleDb.OleDbDataAdapter
    Private m_cbCommandBuilder As OleDb.OleDbCommandBuilder
    Private m_dtJobs As New DataTable
    Private m_rowposition As Integer = 0
 
    Private Sub cbJobType_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbJobType.SelectedIndexChanged
        cbJobSubType.Enabled = True
        If cbJobType.Text = "Technology" Then
            cbJobSubType.Items.Clear()
            cbJobSubType.Items.Add("Analyst")
            cbJobSubType.Items.Add("Business Systems")
            cbJobSubType.Items.Add("Consultant")
            cbJobSubType.Items.Add("Database Administrator")
            cbJobSubType.Items.Add("Database Developer / Engineer")
        End If
        If cbJobType.Text = "Telecommunications" Then
            cbJobSubType.Items.Clear()
            cbJobSubType.Items.Add("Engineer")
            cbJobSubType.Items.Add("Field Technician")
            cbJobSubType.Items.Add("Project Management")
            cbJobSubType.Items.Add("Product Management")
            cbJobSubType.Items.Add("Software / Applications Engineer")
        End If
    End Sub
 
 
    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.Close()
    End Sub
 
    Private Sub btnPost_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPost.Click
 
 
        Dialog1.Show()
        newjob_ID = tbJobID.Text
        newjob_Title = tbJobTitle.Text
        newjob_Type = cbJobType.Text
        newjob_SubType = cbJobSubType.Text
        newjob_Years = cbYears.Text
        newjob_Location1 = tbLocation1.Text
        newjob_Location2 = tbLocation2.Text
        newjob_Description = rtbDescription.Text
        newjob_Map = cbMap.Text
        newjob_Keywords = tbKeywords.Text
 
        Dim drNewRow As DataRow = m_dtJobs.NewRow()
 
        drNewRow("JobID") = tbJobID.Text
        drNewRow("JobTitle") = tbJobTitle.Text
        drNewRow("JobCategory") = cbJobType.Text
        drNewRow("jobSubCategory") = cbJobSubType.Text
        drNewRow("JobExperience") = cbYears.Text
        drNewRow("JobLocation1") = tbLocation1.Text
        drNewRow("JobLocation2") = tbLocation2.Text
        drNewRow("JobDescription") = rtbDescription.Text
        drNewRow("jobMap") = cbMap.Text
        drNewRow("jobKeywords") = tbKeywords.Text
 
        m_dtJobs.Rows.Add(drNewRow)
        m_dadataadapter.Update(m_dtJobs)
        m_rowposition = m_dtJobs.Rows.Count - 1
 
 
 
 
 
 
        Dialog1.Close()
        MessageBox.Show("Success!")
        Me.Close()
 
 
    End Sub
 
    Private Sub btnMapInfo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMapInfo.Click
        MapInfo.Show()
    End Sub
 
    Private Sub NewJob_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
 
        m_cnadonetconnection.Close()
        m_cnadonetconnection.Dispose()
 
    End Sub
 
    Private Sub NewJob_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        m_cnadonetconnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\database\SKYFIRMJACKSON.mdb"
        m_cnadonetconnection.Open()
        m_dadataadapter = New OleDb.OleDbDataAdapter("Select * From JOBS", m_cnadonetconnection)
        m_cbCommandBuilder = New OleDb.OleDbCommandBuilder(m_dadataadapter)
        m_dadataadapter.Fill(m_dtJobs)
 
 
    End Sub
End Class

Open in new window

0
Comment
Question by:SkyFirm
[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
  • 2
  • 2
8 Comments
 
LVL 75
ID: 21818119
That's correct.  Until A2007, RFT is not supported.

mx
0
 
LVL 75
ID: 21818123
However, I have successfully used this free tool:

http://www.lebans.com/richtext.htm

mx
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 21818125
Hi SkyFirm,

You have to save as Rtf format instead of Text. You need to use the property rtf

Me.RichTextBox1.Rtf
0
Technology Partners: 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!

 
LVL 48

Accepted Solution

by:
jpaulino earned 500 total points
ID: 21818163
DatabaseMX,

If you save to the database as Rtf format it will save the format also (as plain text but with the formatting). The db field can be defined as text.

This is "jpaulino" in green with Microsoft Sans Serif font.

"{\rtf1\ansi\ansicpg1252\deff0\deflang2070{\fonttbl{\f0\fnil\fcharset0 Microsoft Sans Serif;}}
{\colortbl ;\red0\green128\blue0;}
\viewkind4\uc1\pard\cf1\f0\fs17 jpaulino\cf0\par}"

When you retrive form the db (access, sql, etc) you set it again like:

Me.RichTextBox1.Rtf = MyFieldFromDB
0
 
LVL 50

Expert Comment

by:Gustav Brock
ID: 21819620
> The db field can be defined as text.

Minor correction: For all practical purposes, it should be defined as Memo.

mx: You are thinking of the HTML formatted rich text control of A2007. That is, of course, different from the original Rich Text Control of previous versions which used RTF formatting.

/gustav
0
 
LVL 75
ID: 21819650
"That's correct.  Until A2007, RFT is not supported."

Actually, I'm thinking of the fact the A2007 supports Rich Text in text boxes - not a control.

From:

http://msdn.microsoft.com/en-us/library/bb203849.aspx


"Replacing Code and Third-Party Controls"
 .........

"Saving Rich Text in a Field

In an Access 2007 Text field or Memo field, you have the option of saving unformatted text (as you always have in Access) or saving rich texttext that contains formatting such as bold and italic. To store rich text, you need to use a Text Box control on a form with its Text Format property set to Rich Text, as shown in Figure 25."
0
 
LVL 50

Expert Comment

by:Gustav Brock
ID: 21819666
Right, but that "rich text" is not RTF Rich Text but HTML. Not that this is bad, but it is somewhat confusing (at least it was to me).

/gustav
0
 
LVL 75
ID: 21819680
oops ...further down:

"Because Access 2007 stores its rich text in HTML format, instead of the Rich Text Format (RTF) format used by several third-party controls, you cannot just replace an ActiveX control with an Access 2007 control that provides similar functionality. If you are currently using a third-party control, and you have already stored RTF data in your database, you should continue using the existing control. If you are newly adding support for rich text to your application, however, use the new text box option instead."

Well ... still ... it's not a control.

mx
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

738 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