Microsoft KB Archive/231726

= How To Export a DataReport to an RTF file =

Article ID: 231726

Article Last Modified on 7/1/2004

-

APPLIES TO


 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q231726



SUMMARY
If users want to export a Visual Basic DataReport to an .Rtf file, they must use automation. There is not a built-in option to send the report directly to this file format. You can send a report to a .Txt file, and then use OLE automation to save that file as a .Rtf file.



MORE INFORMATION
Steps to Accomplish:  Create a Standard EXE Project in Visual Basic. Form1 is created by default. From the Project menu, select Add Data Report and Add Data Environment. In the DataEnvironment, create a Connection to the Nwind.MDB and add a command that uses the Customers table. Drag-and-drop the CustomerID and CompanyName fields to the Detail Band of the DataReport. Select the DataReport and, in the Properties sheet window, set the DataSource property to DataEnvironment1. Set the DataMember property to Command1. Select Form1 and add a CommandButton. Change the Caption property to Show Report. In the Click event for the CommandButton, add the line: DataReport1.Show.   Add another CommandButton and change the Caption property to Export Report. Add the following code to the Click event: ' export report to TXT file DataReport1.ExportReport rptKeyText, "c:\Report\mytext1.txt"

Dim obj As Object Set obj = CreateObject("Word.basic") obj.fileopen "c:\report\mytext1.txt" obj.FileSaveAs "c:\report\myrtf.rtf", 6 Set obj = Nothing MsgBox "Your document was converted to RTF format" </li> Be sure that the folder "C:\Report" exists.</li> Press the F5 key to run the program. Click the Show Report button to see the information from the Customers table. Click the Export Report button to export to the .Txt file, and subsequently create the .Rtf file.</li></ol>

Keywords: kbhowto kbaddin kbreportwriter KB231726

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.