p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/)
-   Pro VB Databases (http://p2p.wrox.com/pro-vb-databases-81/)
-   -   crystal report export using vb6 (http://p2p.wrox.com/pro-vb-databases/24975-crystal-report-export-using-vb6.html)

mycha_2003 February 3rd, 2005 12:54 AM

crystal report export using vb6
 
i am using vb6 crystal report 9, i want create a report to view the screen and automaticall export pdf , or excel , i am using the following Code.
    Dim conn As ADODB.Connection
    Dim Rs As ADODB.Recordset
    Dim crystal As CRAXDRT.Application
    Dim report As CRAXDRT.report
    Dim sSQL As String
    Dim CRXDATABASETABLE As CRAXDRT.DatabaseTable

    CRViewer.DisplayBorder = False
    CRViewer.DisplayTabs = False
    CRViewer.EnableDrillDown = False
    CRViewer.EnableRefreshButton = False

    Set conn = New ADODB.Connection
    conn.CursorLocation = adUseClient
    conn.ConnectionString = "Provider=SQLOLEDB;DATA SOURCE=dbserver;DATABASE=supply;USER ID=sa;PASSWORD=sa"
    conn.Open


    Set Rs = New ADODB.Recordset

        sSQL = ""
        sSQL = "Select * From TblSup_EnquiryH, TblJobSheet, TblSup_EnquiryD, TblSup_EnquiryE "
        sSQL = sSQL & " Where TblJobSheet.JobNumber = TblSup_EnquiryH.JobNumber "
        sSQL = sSQL & " and TblSup_EnquiryD.JobNumber = TblSup_EnquiryH.JobNumber "
        sSQL = sSQL & " and TblSup_EnquiryE.JobNumber = TblSup_EnquiryH.JobNumber "
        sSQL = sSQL & " and TblSup_EnquiryH.JobNumber = " & 12013
        sSQL = sSQL & " and TblSup_EnquiryE.PatchNo = " & "'" & "SE1" & "'"



    Rs.Open sSQL, conn, adOpenStatic, adLockReadOnly
    Set crystal = New CRAXDRT.Application 'MANAGES REPORTS
    Set report = crystal.OpenReport("C:\pALCOLATEST\PALCO\REPORT\RP TSUPPLIERENQUIRY5.RPT")
    For Each CRXDATABASETABLE In report.Database.Tables
        CRXDATABASETABLE.ConnectionProperties("USER ID") = "sa"
        CRXDATABASETABLE.ConnectionProperties("password") = "sa"
    Next CRXDATABASETABLE


    report.DiscardSavedData
    report.Database.SetDataSource Rs
    CRViewer.ReportSource = report
    CRViewer.ViewReport
    Do While CRViewer.IsBusy
        DoEvents
    Loop
    report.ExportOptions.DiskFileName = "c:\PalcoLatest\Palco\Report\supEnquiry.XLS"
    report.ExportOptions.DestinationType = crEDTDiskFile
    report.ExportOptions.FormatType = crEFTExcel50
    report.Export False
    CRViewer.Zoom 94
    Rs.Close
    Set Rs = Nothing
    conn.Close
    Set conn = Nothing
    Set crystal = Nothing
    Set report = Nothing
--- end

Note : i have created report earlier using ODBC , tHIS CODE USING OLEDB CONNECTION. SOME TIME THIS CODE GIVEN SOME NETWORK ERROR IT AFFECTED OTHER NETWORK ALSO. I NEED TO VIEW THE REPORT AND EXPORT EXCEL OR PDF USING SQLQUERY.
PLS HELP ME MY PROBLEM.
BY
CHANDRA.




lakpriya March 29th, 2016 04:04 AM

Public HR As New ADODB.Connection
Public Function DBConnect()


Set HR = New ADODB.Connection

HR.Open "DATABASE=" & DatabseName & ";UID=" & UserName & ";PWD=" & Password & ";DSN=" & DSNName '& "'"

End Function


Dim FromDate As Date
Dim ToDate As Date
Dim x As String

x = DateAdd("d", -1, Now)

'FromDate = Format(X, "mm-dd-yyyy")
Set DBCon = New DBManage
DBCon.DBConnect
Set recCom = New Recordset
sSql = "exec OrderT '" & Format(x, "mm-dd-yyyy") & "','" & Format(x, "mm-dd-yyyy") & "'"
DBCon.HR.Execute (sSql)
DBCon.DBDisconnect

SLR_ASupCReport.Connect = "DSN=DSNName;UID=sa;PWD=xxxx;DSQ=dbname;"


SLR_ASupCReport.ReportFileName = app.Path + "\Reports\Order Summary.rpt"

SLR_ASupCReport.DiscardSavedData = True

SLR_ASupCReport.Action = 1

SLR_ASupCReport.WindowTitle = "Order vs Invoice Analysis"
SLR_ASupCReport.ReportTitle = "Order vs Invoice Analysis"
SLR_ASupCReport.DiscardSavedData = False

' crystal report to pdf export
' CRAXDRT dll down load and register
Dim crxApplication As CRAXDRT.Application
Dim oReport As CRAXDRT.Report
Dim crxExportOptions As CRAXDRT.ExportOptions

Set crxApplication = New CRAXDRT.Application
Set oReport = crxApplication.OpenReport(app.Path + "\Reports\Order Details.rpt", 1)
oReport.Database.LogOnServer "p2sodbc.dll", "DSNNAME", "", "USERNAME", "PASSWORD"
With oReport
With .ExportOptions
.UseReportDateFormat = True
.UseReportNumberFormat = True
.FormatType = crEFTPortableDocFormat
.DestinationType = crEDTDiskFile
.DiskFileName = app.Path + "\PDF\Order Details" + Format(Now, "mm-dd-yyyy") + ".pdf"

End With
.Export False
End With


All times are GMT -4. The time now is 10:11 AM.

Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
2013 John Wiley & Sons, Inc.