• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 270
  • Last Modified:

RichTextBox

I need to be able to have a richtextbox that contains text that needs to be filled with results from another form.  It is like a questionaire and I want the results displayed in the RichTextBox within an rtf I have already loaded.  For example the template has the text Company Name:  I want the text from the form that is already filled out to appear next to the Company Name: <text from other form>  I know how to get it from the other form what I don't know is how to format it in the rtf.

Thanks in advance!
0
kmdisney
Asked:
kmdisney
1 Solution
 
vbWhizCommented:
I have used the RichTextBox for creating form letters many times. The best solution I have come up with is like this:

Insert Certain Text into the letter in the richtextbox like '<<FirstName>>' then when placing the actual values into the letter use RichTextBox's built in search to replace '<<FirstName>>' with the actual value from the textbox.

To make life easier you could name each textbox from the form something intellegible like 'FirstName' or 'Address'. In the letter you would insert the names of the fields like this '<<FirstName>>' or '<<Address>>' to separate the fields from the rest of the text. Then you could use a routine like this to place the values into the RichTextBox - replacing the ugly '<<FirstName>>' type stuff.

SAMPLE CODE:

Public Sub InsertValues(TheSourceForm As Form)

Dim Ctrl As Control

For Each Ctrl In TheSourceForm.Controls

    If TypeOf Ctrl Is TextBox Then
        Do
            If Me.RichTextBox1.Find("<<" & Ctrl.Name & ">>") = -1 Then Exit Do
            Me.RichTextBox1.SelText = Ctrl.Text
        Loop
    End If
   
Next Ctrl

End Sub

To use this place a button on a form and on the click event insert some code like this:

RichTextForm.InsertValues Me


This will send the current form to the RichTextForm as a variable and allow the routine to cycle thru all the controls.

All you have to do now is create the other form. Name the fields and try it out!!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now