Link to home
Start Free TrialLog in
Avatar of davoman
davomanFlag for United Kingdom of Great Britain and Northern Ireland

asked on

exporting to excel through crviewr

hi i hope this is an easy one I am using crystal 8.5 and vb 6.0 using a crviewer in vb 6.0 i am exporting to excel.

This works fine except there are no column headings. Yet here are when i open the report in crystal and export.

Is there there a quick way to get the column headings
Avatar of Mike McCracken
Mike McCracken

How are you exporting the data from VB?  What is the code?

mlmcc
Avatar of davoman

ASKER

Public Sub ShowReportsExcel(ByVal strquery As String, strpath As String, strOutput As String)
On Error GoTo Error_check

Dim CRVAppl As CRAXDRT.Application
Dim CRReport As CRAXDRT.Report
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Set CRReport = Nothing


Set CRVAppl = New CRAXDRT.Application
Set CRReport = CRVAppl.OpenReport(strpath)
CRReport.DiscardSavedData


cn.ConnectionString = "Provider = SQLOLEDB;Integrated Security=SSPI;Persist Security Info=False;User ID=sa;" & _
                        "Data Source=Server1;" & _
                        "Initial Catalog=FordContact"
cn.Open
rs.Open strquery, cn, adOpenKeyset
CRReport.Database.SetDataSource rs


Screen.MousePointer = vbHourglass
CRReport.ExportOptions.DestinationType = crEDTDiskFile
CRReport.ExportOptions.FormatType = crEFTExcel80
CRReport.ExportOptions.FormatType = crEFTExcel80Tabular


CRReport.ExportOptions.DiskFileName = "c:\my documents\" & strOutput
CRReport.Export False




Screen.MousePointer = vbDefault
MsgBox "Your report has been exported to c:\my documents\" & strOutput
Else
    MsgBox "There were no records to show or the report could not be created"
    Exit Sub
End If

Error_out:
Exit Sub

Error_check:

MsgBox "There has been and error. Please see the system administrator" & vbCr & vbCr & Err.Number & vbCr & Err.Description
Resume Error_out
End Sub

The code created with the help of your good self mimcc :)
Avatar of davoman

ASKER

rs.Open strquery, cn, adOpenKeyset

If rs.RecordCount > 0 Then
CRReport.Database.SetDataSource rs

sorry missed a bit

ASKER CERTIFIED SOLUTION
Avatar of Mike McCracken
Mike McCracken

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of davoman

ASKER

Just the job!! Thanks once again
Glad to help

mlmcc