Hi all
I am getting an access denied error ( error code -2147206458) when i try to use the export option. does anyone has any clue about it? Also on the machine on which i am trying this out, it works with one of the ID's but with id i am trying it fails.
Attached is the code which we are using.
Public Function DO_Crystal(iFileNum As Integer, szRunDate As String, szRunState As String, szRptCode As String, szBrkStr As Integer, szBrkEnd As Integer, szPageCnt As Integer, szReportName As String) As Integer
Dim Report As CRAXDDRT.Report
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim crystal As CRAXDDRT.Application
Dim iRetval As Integer
Dim szsql As String
Dim sPrnName As String
Dim sCmd As String
Dim sPDFPath As String
On Error GoTo Err_handler
CrystalActiveXReportViewer
1.EnableRe
freshButto
n = False
Set conn = New ADODB.Connection
conn.ConnectionString = "DRIVER={SQL Server};" _
& "SERVER=" + gCtlServer + ";" _
& "DATABASE=" + gCtlAggrDb + ";" _
& "UID=" + GsUserID + ";" _
& "PWD=" + GsPassword + ";"
conn.Open
szsql = "UPDATE Trig_Tbl"
szsql = szsql + " SET run_state = '" + "CRB" + "' "
szsql = szsql + " WHERE run_date = '" + szRunDate + "'"
szsql = szsql + " AND report_code = '" + szRptCode + "'"
conn.Execute szsql
Set rs = New ADODB.Recordset
Select Case szReportName
Case "LB.rpt":
rs.Open "select * from fl_1_bl", conn, adOpenStatic, adLockReadOnly
sPrnName = gszBPrinterName
Case "L31.rpt":
rs.Open "select * from fl_2_bl", conn, adOpenStatic, adLockReadOnly
sPrnName = gszLPrinterName
Case "L60.rpt":
rs.Open "select * from Lp_3_fl", conn, adOpenStatic, adLockReadOnly
sPrnName = gszLPrinterName
Case "IL31.rpt":
rs.Open "select * from lp_4_fl", conn, adOpenStatic, adLockReadOnly
sPrnName = gszLPrinterName
Case "IL60.rpt":
rs.Open "select * from mac_1", conn, adOpenStatic, adLockReadOnly
sPrnName = gszLPrinterName
'Tcs change begins - 07/19/2005
Case "PerInf.rpt"
rs.Open "select * from dbo.PerInftbl", conn, adOpenStatic, adLockReadOnly
sPrnName = gszLPrinterName ' change 1
Case "PerInf_ErrRpt.rpt"
rs.Open "select * from dbo.PerInftbl", conn, adOpenStatic, adLockReadOnly
sPrnName = gszLPrinterName ' change 1
'Tcs change ends - 07/19/2005
End Select
MsgBox "Setting New Crytal Object"
Set crystal = New CRAXDDRT.Application
MsgBox "Setting New Crytal Object - Done"
Set Report = crystal.OpenReport(gszRptF
ileLoc + "\" + Trim(szReportName), 0)
MsgBox "Opened Report" & gszRptFileLoc & "\" & Trim(szReportName)
Report.DiscardSavedData
Report.Database.SetDataSou
rce rs
MsgBox "Setting Crystal ReportViewer "
CrystalActiveXReportViewer
1.ReportSo
urce = Report
MsgBox "Setting Export Options 1"
Report.ExportOptions.Desti
nationType
= crEDTDiskFile
Report.ExportOptions.Forma
tType = crEFTPortableDocFormat
Report.DisplayProgressDial
og = False
MsgBox "Setting Export Options 1 - Done"
If szReportName = "LB.rpt" Then
gszRptFileLoc = gszRptFileLoc + "\B"
'Tcs change begins - 07/19/2005
ElseIf szReportName = "PerInf.rpt" Then
gszRptFileLoc = gszRptFileLoc + "\Inf"
ElseIf szReportName = "PerInf_ErrRpt.rpt" Then
gszRptFileLoc = gszRptFileLoc + "\Inf"
Else
'Tcs change ends - 07/19/2005
gszRptFileLoc = gszRptFileLoc + "\L"
End If
MsgBox gszRptFileLoc
If Len(Trim(Str$(szBrkStr))) = 1 Then
'Tcs change begins - 07/19/2005
If szReportName = "PerInf.rpt" _
Or szReportName = "PerInf_ErrRpt.rpt" Then
Report.ExportOptions.DiskF
ileName = gszRptFileLoc + "\PERIINFL" + szRptCode + "_" + Mid(szRunDate, 1, 2) + Mid(szRunDate, 4, 2) + Mid(szRunDate, 7, 4) + "_0" + Trim(Str$(szBrkStr)) + ".PDF"
Else
Report.ExportOptions.DiskF
ileName = gszRptFileLoc + "\" + szRptCode + "_" + Mid(szRunDate, 1, 2) + Mid(szRunDate, 4, 2) + Mid(szRunDate, 7, 4) + "_0" + Trim(Str$(szBrkStr)) + ".PDF"
End If
'Tcs change ends - 07/19/2005
Else
'Tcs change begins - 07/19/2005
If szReportName = "PerInf.rpt" _
Or szReportName = "PerInf_ErrRpt.rpt" Then
Report.ExportOptions.DiskF
ileName = gszRptFileLoc + "\PERIINFL" + szRptCode + "_" + Mid(szRunDate, 1, 2) + Mid(szRunDate, 4, 2) + Mid(szRunDate, 7, 4) + "_" + Trim(Str$(szBrkStr)) + ".PDF"
Else
Report.ExportOptions.DiskF
ileName = gszRptFileLoc + "\" + szRptCode + "_" + Mid(szRunDate, 1, 2) + Mid(szRunDate, 4, 2) + Mid(szRunDate, 7, 4) + "_" + Trim(Str$(szBrkStr)) + ".PDF"
End If
'Tcs change ends - 07/19/2005
End If
MsgBox "Set Disk File Name"
If szBrkStr = szBrkEnd Then
If szBrkStr = 1 Then
Report.ExportOptions.PDFEx
portAllPag
es = True
Else
Report.ExportOptions.PDFEx
portAllPag
es = False
Report.ExportOptions.PDFFi
rstPageNum
ber = ((szBrkStr - 1) * 4000) + 1
Report.ExportOptions.PDFLa
stPageNumb
er = szPageCnt * 2 + 2
End If
Else
If szBrkStr = 1 Then
Report.ExportOptions.PDFEx
portAllPag
es = False
Report.ExportOptions.PDFFi
rstPageNum
ber = ((szBrkStr - 1) * 4000) + 1
Report.ExportOptions.PDFLa
stPageNumb
er = ((szBrkStr - 1) * 4000) + 4000
Else
Report.ExportOptions.PDFEx
portAllPag
es = False
Report.ExportOptions.PDFFi
rstPageNum
ber = ((szBrkStr - 1) * 4000) + 1
Report.ExportOptions.PDFLa
stPageNumb
er = ((szBrkStr - 1) * 4000) + 4000
End If
End If
MsgBox "Set report option 2 - Done"
MsgBox "Before Export" ' Fails after this step
Report.Export (False)
MsgBox "After Export"
If Not cSetPrinter.SetPrinterAsDe
fault(sPrn
Name) Then
If WriteFileRow(iFileNum, "Error Setting up the Milville printer as default") = False Then GoTo Do_CrystalErr
End
End If
MsgBox "Printer Set"
MsgBox "PDF Path to be set"
sPDFPath = Report.ExportOptions.DiskF
ileName
MsgBox "PDF path set"
iRetval = PrintPDFs(iFileNum, sPrnName, sPDFPath)
MsgBox "made PDF"
sPrnName = cSetPrinter.m_sPrevPrinter
DevName
If Not cSetPrinter.SetPrinterAsDe
fault(sPrn
Name) Then
If WriteFileRow(iFileNum, "Error reverting the old printer as default") = False Then GoTo Do_CrystalErr
End
End If
rs.Close
conn.Close
DO_Crystal = FnReturnValue.success
Set conn = Nothing
Set crystal = Nothing
Set Report = Nothing
Set rs = Nothing
Exit Function
Do_CrystalErr:
WriteFileRow iFileNum, CStr(Err.Number) + " - " + CStr(Err.Description) + " - Source : DO_Crystal "
Exit Function
Err_handler:
MsgBox Err.Number & vbCrLf & Err.Description
End Function