ACC2000: How to Format Words on a Control in a Report (310802)



The information in this article applies to:

  • Microsoft Access 2000

This article was previously published under Q310802
Moderate: Requires basic macro, coding, and interoperability skills.

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).

SUMMARY

This article shows how to format words on a control in a report. The article uses an example from the Northwind database, a text box composed of concatenated first and last name fields from the Employees table.

MORE INFORMATION

The following example demonstrates the procedure for making the firstname field in the text box bold while keeping the lastname field normal in a report.
  1. Copy Microsoft Rich TextBox ActiveX Control (the Richtx32.ocx file) to the C:\Windows\System folder. Make sure that you copy version 6.0.88.4 or later of the Richtx32.ocx file.

    Version 6.0.88.4 or later of the Richtx32.ocx file comes with Microsoft Visual Studio 6.0 Service Pack 4 (SP4) or later. If you do not have the appropriate version, you can download Visual Studio 6.0 SP5 from the following Web site, and then run the update to obtain the correct version of the file:

    Note that to be able to run the update, you must have at least one of the Visual Studio programs installed on your computer. Also, there is a problem with the Rich TextBox Control. For additional information, click the article number below to view the article in the Microsoft Knowledge Base:

    212733 FIX: Contents of Rich TextBox Control Not Viewable in Report

  2. Register the Rich TextBox Control by using the Regsvr32.exe program:
    1. Click Start, and then click Run.
    2. In the Open box, type the following command, and then press ENTER:

      Regsvr32 C:\Windows\System\Richtx32.ocx

  3. Create a concatenated field in a query that contains first and last names from the Employees table:
    1. In the Database window in Access 2000, click Queries under Objects, and then click New.
    2. In the New Query dialog box, click Design View, and then click OK.
    3. In the Show Table dialog box, click the Employees table on the Tables tab, click Add, and then click Close.
    4. In the Field box in the query design grid, type the following:

      concatenate: [firstname] & " " & [lastname]

    5. On the File menu, click Save, type a name for the query, and then click OK.
  4. Create a report that is based on the query and that uses the Rich TextBox ActiveX Control:
    1. In the Database window, click Reports under Objects, and then click New.
    2. In the New Report dialog box, click Design View, click the newly created query in the Choose the table or query where the object's data comes from box, and then click OK.
    3. On the Insert menu, click ActiveX Control.
    4. In the Select ActiveX Control dialog box, click Microsoft Rich TextBox Control 6.0 (SP4), and then click OK.
    5. Right-click the inserted Rich TextBox control, and then click Properties.
    6. On the Data tab, make sure that concatenate is listed in the Control Source box.
  5. Right-click the Detail section on the report, and then click Build Event.
  6. In the Choose Builder dialog box, click Code Builder, and then click OK.
  7. Under the Detail_Format event, type the following code:
    Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    
    Dim theFirstName As String
    Dim theLastName As String
    
    theFirstName = Left(Me.concatenate.Value, InStr(1, Me.concatenate.Value, " "))
    theLastName = Mid(Me.concatenate.Value, InStr(1, Me.concatenate.Value, " ") +1)
    
    With ActiveXCtl15
    'You need to replace ActiveXCt115 with the name of the Rich TextBox 
    'control that you inserted.
    
    .SelBold = True
    .SelText = theFirstName
    .SelBold = False
    .SelText = theLastName
    
    End With
    
    End Sub
    					
  8. Preview the report.
Note that Print Preview may be blank on the ActiveX control. However, you can print the report to view the results. For additional information, click the article number below to view the article in the Microsoft Knowledge Base:

212733 FIX: Contents of Rich TextBox Control Not Viewable in Report


Modification Type:MinorLast Reviewed:7/13/2004
Keywords:kbhowto KB310802 kbAudDeveloper