Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can i use crystal to write a report from text 1

Status
Not open for further replies.

JSeidel

Technical User
Jan 10, 2003
77
US
I am looking to write a report from a word document - is this possible? if not - can I write a script and have crystal call the script for the values?

please help!

thanks so much
 
I do not think you can write a report directly from a Word Doc. But is you can save it as a text file then you can report off the converted text file using ODBC and setting up a DSN using the text driver.
 
Word is an unusual choice for a data container...

Another option might be to write a macro in Word to export the data to an Access database each time the user saves the .doc, then point your report to the Access database.

If it's meaningful data, get it out of Word as soon as possible.

-k kai@informeddatadecisions.com
 
Here's my VB6 code for passing data from .csv text files to a Crystal 8.5 report that also contains a subreport:

Private Sub Form_Load()

'*************************************************************
'PARSE THE COMMAND-LINE EXECUTABLE
'*************************************************************
'A directory folder is created by another program on the fly
'to hold the source data files created each time the report is requested.
'The folder name will vary each time the report is run.

'The name of the newly created folder is passed
'as a command line switch when this executable is launched.
'Parse the command line contents to extract the
'folder name and store it as a variable.
'Executable command line format is as follows:
'[VB6_program_name].exe/[source data folder name]

'Set a variable to hold # of chars in folder name
varFolderLen = Len(Command) - 1

'Set a variable to contain the folder name
varFolder = Right(Command, varFolderLen)

'Uncomment this line to verify report path
'MsgBox "SELECT * FROM " & App.Path & "\" & varFolder & "\" & "[main_report_datafile].csv", vbOKOnly


'*************************************************************
'SET THE REPORT OBJECT
'*************************************************************
Dim crxReport As CRAXDRT.Report
Set crxReport = crxApplication.OpenReport(App.Path & "\[main_report_name].rpt")

Dim crxSubreport As CRAXDRT.Report
Set crxSubreport = crxReport.OpenSubreport("[subreport_name].rpt")

crxReport.Database.SetDataSource Read_Text_File_Main, 3, 1

crxSubreport.Database.SetDataSource Read_Text_File_Sub, 3, 1



'************************************************************
'SET .PDF PARAMETERS AND OPTIONS
'************************************************************
'This report is set to automatically export to Adobe Acrobat
'(.pdf) format with no user prompts or interaction

'specify pdf format for output file
crxReport.ExportOptions.FormatType = crEFTPortableDocFormat

'Assign the export file name and location - exported file will
'be stored in the same folder where source data resides, and will
'be named with the same name as that folder + .pdf file extension
crxReport.ExportOptions.DiskFileName = varFolder & "\" & varFolder & ".pdf"

'Set option to export all pages of report to .pdf file to true
crxReport.ExportOptions.PDFExportAllPages = True

'Uncomment this line to display a progress bar as report is exported
'crxReport.DisplayProgressDialog = chkProgress.Value



'*************************************************************
'RUN THE EXPORT
'*************************************************************

'Export report without prompting user
'Note that setting the argument to False will fail if your CR Server doesn't
'have all the most up-to-date DLLs for report exporting.
'Setting the arg to True will avoid that problem, but will also cause
'a dialog to pop up during the export and prompt the user to specify
'filename and location.
crxReport.Export (False)


'Let the user know when the export is done
MsgBox "Report export to Adobe Acrobat (.pdf) format complete.", vbOKOnly + vbInformation, "Report Exported"


'*************************************************************
'CLOSE THE APPLICATION WINDOW, SHUT DOWN
'*************************************************************
Unload Me

End Sub


Private Function Read_Text_File_Main() As ADODB.Recordset

Dim rsMain As ADODB.Recordset
Set rsMain = New ADODB.Recordset
Dim connMain As ADODB.Connection
Set connMain = New ADODB.Connection
connMain.Open "DRIVER={Microsoft Text Driver (*.txt; *.csv)}" & _
";DBQ=" & App.Path & "\" & varFolder & "\" & _
";DefaultDir=" & App.Path & _
";Uid=Admin;Pwd=;"

rsMain.Open "SELECT * FROM " & App.Path & "\" & varFolder & "\[main_report_datafile].csv", connMain, adOpenStatic, adLockReadOnly, adCmdText
Set Read_Text_File_Main = rsMain
Set rsMain = Nothing
Set connMain = Nothing
End Function

Private Function Read_Text_File_Sub() As ADODB.Recordset

Dim rsSub As ADODB.Recordset
Set rsSub = New ADODB.Recordset
Dim connSub As ADODB.Connection
Set connSub = New ADODB.Connection
connSub.Open "DRIVER={Microsoft Text Driver (*.txt; *.csv)}" & _
";DBQ=" & App.Path & "\" & varFolder & "\" & _
";DefaultDir=" & App.Path & _
";Uid=Admin;Pwd=;"

rsSub.Open "SELECT * FROM " & App.Path & "\" & varFolder & "\[subreport_datafile].csv", connSub, adOpenStatic, adLockReadOnly, adCmdText
Set Read_Text_File_Sub = rsSub
Set rsSub = Nothing
Set connSub = Nothing
End Function


Private Sub Form_Unload(Cancel As Integer)
'Set the objects to 'Nothing' to remove them from memory.
'This ensures that each time you use these objects
'they are recreated and populated with new data.

Set crxReport = Nothing
Set crxSubreport = Nothing

End Sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top